@maestro-org/typescript-sdk
Version:
TypeScript SDK for the Maestro Dapp Platform
66 lines (57 loc) • 2.02 kB
text/typescript
import globalAxios, { AxiosInstance, AxiosRequestConfig } from 'axios';
export type MaestroSupportedNetworks = 'Mainnet' | 'Preprod' | 'Preview';
export interface ConfigurationParameters {
readonly apiKey?: string;
readonly baseUrl?: string;
readonly network: MaestroSupportedNetworks;
readonly baseOptions?: AxiosRequestConfig;
readonly axiosInstance?: AxiosInstance;
}
export class Configuration {
/**
* parameter for apiKey security
* @param name security name
* @memberof Configuration
*/
readonly apiKey: string;
/**
* base url of network request
*
* @type {string}
* @memberof Configuration
*/
readonly baseUrl: string;
/**
* base options for axios calls
*
* @type {AxiosRequestConfig}
* @memberof Configuration
*/
readonly baseOptions?: AxiosRequestConfig;
readonly axiosInstance: AxiosInstance;
constructor(param: ConfigurationParameters) {
if (param.baseUrl) {
this.baseUrl = param.baseUrl;
} else {
this.baseUrl = `https://${param.network}.gomaestro-api.org/v1`;
}
this.apiKey = param.apiKey || '';
this.baseOptions = param.baseOptions;
this.axiosInstance = param.axiosInstance ?? globalAxios;
}
/**
* Check if the given MIME is a JSON MIME.
* JSON MIME examples:
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* @param mime - MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
public isJsonMime(mime: string): boolean {
// eslint-disable-next-line prefer-regex-literals, no-control-regex
const jsonMime: RegExp = new RegExp('^(application/json|[^;/ \t]+/[^;/ \t]+[+]json)[ \t]*(;.*)?$', 'i');
return mime !== null && (jsonMime.test(mime) || mime.toLowerCase() === 'application/json-patch+json');
}
}