This repository has been archived by the owner on Feb 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added GetAllContactMessages feature. Added GetSingleContactMessage fe…
…ature. Restructured request interface.
- Loading branch information
Showing
12 changed files
with
357 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,55 @@ | ||
import axios, { AxiosInstance } from "axios"; | ||
import { PortfolioRequest } from "./request"; | ||
|
||
export type Headers = { [headerName: string]: any }; | ||
|
||
export interface ClientConfig { | ||
host: string; | ||
jwt?: string; | ||
version?: string; | ||
} | ||
|
||
export class ClientConfigWrapper { | ||
private readonly config: ClientConfig; | ||
|
||
constructor(config: ClientConfig) { | ||
this.config = config; | ||
} | ||
|
||
merge = (config: ClientConfig | PortfolioRequest): ClientConfigWrapper => { | ||
const mergedConfig: ClientConfig = { | ||
...this.config, | ||
...config, | ||
}; | ||
return new ClientConfigWrapper(mergedConfig); | ||
}; | ||
|
||
get headers(): Headers { | ||
return { | ||
Authorization: `Bearer ${this.config.jwt}`, | ||
"X-PORTFOLIO-VERSION": this.config.version, | ||
}; | ||
} | ||
|
||
get host(): string { | ||
return this.config.host; | ||
} | ||
|
||
get jwt(): string | undefined { | ||
return this.config.jwt; | ||
} | ||
|
||
get version(): string | undefined { | ||
return this.config.version; | ||
} | ||
} | ||
|
||
export abstract class BaseClient { | ||
readonly config: ClientConfig; | ||
readonly config: ClientConfigWrapper; | ||
protected readonly axiosInstance: AxiosInstance; | ||
|
||
constructor(config: ClientConfig, axiosInstance: AxiosInstance = axios) { | ||
this.config = config; | ||
this.config = new ClientConfigWrapper(config); | ||
this.axiosInstance = axiosInstance; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,21 @@ | ||
import { AxiosRequestConfig } from "axios"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export interface PortfolioRequest<T = any> { | ||
version?: string; | ||
body?: T; | ||
/** | ||
* Represents a portfolio request. | ||
* JWT and Version properties can be used to override initial portfolio client configuration, | ||
* however currently this functionality does not exist | ||
*/ | ||
export interface PortfolioRequest { | ||
jwt?: string; | ||
version?: string; | ||
} | ||
|
||
export const axiosRequestConfig = <T>( | ||
request: PortfolioRequest<T> | ||
): AxiosRequestConfig => { | ||
const headers: { [k: string]: string } = {}; | ||
|
||
if (request.jwt) { | ||
headers["Authorization"] = `Bearer ${request.jwt}`; | ||
} | ||
export interface RequestWithParameters<T> extends PortfolioRequest { | ||
queryParameters?: T; | ||
} | ||
|
||
if (request.version) { | ||
headers["X-PORTFOLIO-VERSION"] = request.version; | ||
} | ||
export interface RequestWithBody<T> extends PortfolioRequest { | ||
body?: T; | ||
} | ||
|
||
return { | ||
headers: { | ||
...headers, | ||
}, | ||
}; | ||
}; | ||
export interface CompletePortfolioRequest<B, Q> | ||
extends RequestWithBody<B>, | ||
RequestWithParameters<Q> {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.