boldsign
Version:
NodeJS client for boldsign
662 lines (571 loc) • 23.5 kB
text/typescript
/**
* BoldSign API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 1
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
import {
ObjectSerializer, Authentication, VoidAuth, Interceptor,
HttpBasicAuth, HttpBearerAuth, ApiKeyAuth, OAuth, RequestFile,
CreateTeamRequest,ErrorResult,TeamCreated,TeamListResponse,TeamResponse,TeamUpdateRequest,
} from '../model';
import {
HttpError,
optionsI,
returnTypeT,
returnTypeI,
generateFormData,
toFormData,
queryParamsSerializer,
USER_AGENT,
} from './';
let defaultBasePath = 'https://api.boldsign.com';
// ===============================================
// This file is autogenerated - Please do not edit
// ===============================================
export class TeamsApi {
protected _basePath = defaultBasePath;
protected _defaultHeaders : any = { 'User-Agent': USER_AGENT };
protected _useQuerystring : boolean = true;
protected authentications = {
'default': <Authentication>new VoidAuth(),
'Bearer': new ApiKeyAuth('header', 'Authorization'),
'X-API-KEY': new ApiKeyAuth('header', 'X-API-KEY'),
}
protected interceptors: Interceptor[] = [];
constructor(basePath?: string) {
if (basePath) {
this.basePath = basePath;
}
}
set useQuerystring(value: boolean) {
this._useQuerystring = value;
}
set basePath(basePath: string) {
this._basePath = basePath;
}
set defaultHeaders(defaultHeaders: any) {
this._defaultHeaders = { ...defaultHeaders, "User-Agent": USER_AGENT };
}
get defaultHeaders() {
return this._defaultHeaders;
}
get basePath() {
return this._basePath;
}
public setDefaultAuthentication(auth: Authentication) {
this.authentications.default = auth;
}
public setApiKey(apikey: string) {
this.authentications["X-API-KEY"].apiKey = apikey;
}
public setAccessToken(accessToken: string) {
this.authentications["Bearer"].apiKey = 'bearer ' + accessToken;
}
public addInterceptor(interceptor: Interceptor) {
this.interceptors.push(interceptor);
}
/**
*
* @summary Create Team.
* @param createTeamRequest team creation.
* @param options
*/
public async createTeam (createTeamRequest: CreateTeamRequest, options: optionsI = {headers: {}}) : Promise<TeamCreated> {
createTeamRequest = deserializeIfNeeded(createTeamRequest, "CreateTeamRequest");
const localVarPath = this.basePath + '/v1/teams/create';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams['content-type'] = 'application/json';
} else {
localVarHeaderParams['content-type'] = produces.join(',');
}
let localVarFormParams: any = {};
let localVarBodyParams: any = undefined;
// verify required parameter 'createTeamRequest' is not null or undefined
if (createTeamRequest === null || createTeamRequest === undefined) {
throw new Error('Required parameter createTeamRequest was null or undefined when calling createTeam.');
}
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
const result = generateFormData(createTeamRequest, CreateTeamRequest);
localVarUseFormData = result.localVarUseFormData;
let data = {};
if (localVarUseFormData) {
const formData = toFormData(result.data);
data = formData;
localVarHeaderParams = {
...localVarHeaderParams,
...formData.getHeaders(),
};
} else {
data = ObjectSerializer.serialize(
createTeamRequest,
"CreateTeamRequest"
);
}
let localVarRequestOptions: AxiosRequestConfig = {
method: 'POST',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
paramsSerializer: this._useQuerystring ? queryParamsSerializer : undefined,
maxContentLength: Infinity,
maxBodyLength: Infinity,
responseType: "json",
};
if (localVarRequestOptions.method !== 'GET') {
localVarRequestOptions.data = data;
}
let authenticationPromise = Promise.resolve();
if (this.authentications["X-API-KEY"].apiKey) {
authenticationPromise = authenticationPromise.then(() => this.authentications["X-API-KEY"].applyToRequest(localVarRequestOptions));
}
if (this.authentications["Bearer"].apiKey) {
authenticationPromise = authenticationPromise.then(() => this.authentications["Bearer"].applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
let interceptorPromise = authenticationPromise;
for (const interceptor of this.interceptors) {
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
}
return interceptorPromise.then(() => {
return new Promise<TeamCreated>((resolve, reject) => {
axios.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse<TeamCreated>(
resolve,
reject,
response,
"TeamCreated",
);
}, (error: AxiosError) => {
if (error.response == null) {
reject(error);
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
200,
"TeamCreated",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
401,
"ErrorResult",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
403,
"ErrorResult",
)) {
return;
}
reject(error);
});
});
});
}
/**
*
* @summary Get Team details.
* @param teamId Team Id.
* @param options
*/
public async getTeam (teamId: string, options: optionsI = {headers: {}}) : Promise<TeamResponse> {
const localVarPath = this.basePath + '/v1/teams/get';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams['content-type'] = 'application/json';
} else {
localVarHeaderParams['content-type'] = produces.join(',');
}
let localVarFormParams: any = {};
let localVarBodyParams: any = undefined;
// verify required parameter 'teamId' is not null or undefined
if (teamId === null || teamId === undefined) {
throw new Error('Required parameter teamId was null or undefined when calling getTeam.');
}
if (teamId !== undefined) {
localVarQueryParameters['teamId'] = ObjectSerializer.serialize(teamId, "string");
}
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let data = {};
if (localVarUseFormData) {
const formData = toFormData(localVarFormParams);
data = formData;
localVarHeaderParams = {
...localVarHeaderParams,
...formData.getHeaders(),
};
}
let localVarRequestOptions: AxiosRequestConfig = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
paramsSerializer: this._useQuerystring ? queryParamsSerializer : undefined,
maxContentLength: Infinity,
maxBodyLength: Infinity,
responseType: "json",
};
if (localVarRequestOptions.method !== 'GET') {
localVarRequestOptions.data = data;
}
let authenticationPromise = Promise.resolve();
if (this.authentications["X-API-KEY"].apiKey) {
authenticationPromise = authenticationPromise.then(() => this.authentications["X-API-KEY"].applyToRequest(localVarRequestOptions));
}
if (this.authentications["Bearer"].apiKey) {
authenticationPromise = authenticationPromise.then(() => this.authentications["Bearer"].applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
let interceptorPromise = authenticationPromise;
for (const interceptor of this.interceptors) {
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
}
return interceptorPromise.then(() => {
return new Promise<TeamResponse>((resolve, reject) => {
axios.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse<TeamResponse>(
resolve,
reject,
response,
"TeamResponse",
);
}, (error: AxiosError) => {
if (error.response == null) {
reject(error);
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
200,
"TeamResponse",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
401,
"ErrorResult",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
403,
"ErrorResult",
)) {
return;
}
reject(error);
});
});
});
}
/**
*
* @summary List Teams.
* @param page Page index specified in get team list request.
* @param pageSize Page size specified in get team list request.
* @param searchKey Teams can be listed by the search key
* @param options
*/
public async listTeams (page: number, pageSize?: number, searchKey?: string, options: optionsI = {headers: {}}) : Promise<TeamListResponse> {
const localVarPath = this.basePath + '/v1/teams/list';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams['content-type'] = 'application/json';
} else {
localVarHeaderParams['content-type'] = produces.join(',');
}
let localVarFormParams: any = {};
let localVarBodyParams: any = undefined;
// verify required parameter 'page' is not null or undefined
if (page === null || page === undefined) {
throw new Error('Required parameter page was null or undefined when calling listTeams.');
}
if (page !== undefined) {
localVarQueryParameters['Page'] = ObjectSerializer.serialize(page, "number");
}
if (pageSize !== undefined) {
localVarQueryParameters['PageSize'] = ObjectSerializer.serialize(pageSize, "number");
}
if (searchKey !== undefined) {
localVarQueryParameters['SearchKey'] = ObjectSerializer.serialize(searchKey, "string");
}
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let data = {};
if (localVarUseFormData) {
const formData = toFormData(localVarFormParams);
data = formData;
localVarHeaderParams = {
...localVarHeaderParams,
...formData.getHeaders(),
};
}
let localVarRequestOptions: AxiosRequestConfig = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
paramsSerializer: this._useQuerystring ? queryParamsSerializer : undefined,
maxContentLength: Infinity,
maxBodyLength: Infinity,
responseType: "json",
};
if (localVarRequestOptions.method !== 'GET') {
localVarRequestOptions.data = data;
}
let authenticationPromise = Promise.resolve();
if (this.authentications["X-API-KEY"].apiKey) {
authenticationPromise = authenticationPromise.then(() => this.authentications["X-API-KEY"].applyToRequest(localVarRequestOptions));
}
if (this.authentications["Bearer"].apiKey) {
authenticationPromise = authenticationPromise.then(() => this.authentications["Bearer"].applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
let interceptorPromise = authenticationPromise;
for (const interceptor of this.interceptors) {
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
}
return interceptorPromise.then(() => {
return new Promise<TeamListResponse>((resolve, reject) => {
axios.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse<TeamListResponse>(
resolve,
reject,
response,
"TeamListResponse",
);
}, (error: AxiosError) => {
if (error.response == null) {
reject(error);
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
200,
"TeamListResponse",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
401,
"ErrorResult",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
403,
"ErrorResult",
)) {
return;
}
reject(error);
});
});
});
}
/**
*
* @summary Update Team.
* @param teamUpdateRequest update team.
* @param options
*/
public async updateTeam (teamUpdateRequest: TeamUpdateRequest, options: optionsI = {headers: {}}) : Promise<returnTypeI> {
teamUpdateRequest = deserializeIfNeeded(teamUpdateRequest, "TeamUpdateRequest");
const localVarPath = this.basePath + '/v1/teams/update';
let localVarQueryParameters: any = {};
let localVarHeaderParams: any = (<any>Object).assign({}, this._defaultHeaders);
const produces = ['application/json'];
// give precedence to 'application/json'
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams['content-type'] = 'application/json';
} else {
localVarHeaderParams['content-type'] = produces.join(',');
}
let localVarFormParams: any = {};
let localVarBodyParams: any = undefined;
// verify required parameter 'teamUpdateRequest' is not null or undefined
if (teamUpdateRequest === null || teamUpdateRequest === undefined) {
throw new Error('Required parameter teamUpdateRequest was null or undefined when calling updateTeam.');
}
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
const result = generateFormData(teamUpdateRequest, TeamUpdateRequest);
localVarUseFormData = result.localVarUseFormData;
let data = {};
if (localVarUseFormData) {
const formData = toFormData(result.data);
data = formData;
localVarHeaderParams = {
...localVarHeaderParams,
...formData.getHeaders(),
};
} else {
data = ObjectSerializer.serialize(
teamUpdateRequest,
"TeamUpdateRequest"
);
}
let localVarRequestOptions: AxiosRequestConfig = {
method: 'PUT',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
paramsSerializer: this._useQuerystring ? queryParamsSerializer : undefined,
maxContentLength: Infinity,
maxBodyLength: Infinity,
responseType: "json",
};
if (localVarRequestOptions.method !== 'GET') {
localVarRequestOptions.data = data;
}
let authenticationPromise = Promise.resolve();
if (this.authentications["X-API-KEY"].apiKey) {
authenticationPromise = authenticationPromise.then(() => this.authentications["X-API-KEY"].applyToRequest(localVarRequestOptions));
}
if (this.authentications["Bearer"].apiKey) {
authenticationPromise = authenticationPromise.then(() => this.authentications["Bearer"].applyToRequest(localVarRequestOptions));
}
authenticationPromise = authenticationPromise.then(() => this.authentications.default.applyToRequest(localVarRequestOptions));
let interceptorPromise = authenticationPromise;
for (const interceptor of this.interceptors) {
interceptorPromise = interceptorPromise.then(() => interceptor(localVarRequestOptions));
}
return interceptorPromise.then(() => {
return new Promise<returnTypeI>((resolve, reject) => {
axios.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse(
resolve,
reject,
response,
);
}, (error: AxiosError) => {
if (error.response == null) {
reject(error);
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
401,
"ErrorResult",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
403,
"ErrorResult",
)) {
return;
}
reject(error);
});
});
});
}
}
function deserializeIfNeeded<T> (obj: T, classname: string): T {
if (obj !== null && obj !== undefined && obj.constructor.name !== classname) {
return ObjectSerializer.deserialize(obj, classname);
}
return obj;
}
type AxiosResolve<T> = (
value: (T | PromiseLike<T>),
) => void
type AxiosReject = (reason?: any) => void;
function handleSuccessfulResponse<T>(
resolve: AxiosResolve<T>,
reject: AxiosReject,
response: AxiosResponse,
returnType?: string,
) {
let body = response.data;
if (
response.status &&
response.status >= 200 &&
response.status <= 299
) {
if (returnType) {
body = ObjectSerializer.deserialize(body, returnType);
}
resolve(body);
} else {
reject(new HttpError(response, body, response.status));
}
}
function handleErrorCodeResponse(
reject: AxiosReject,
response: AxiosResponse,
code: number,
returnType: string
): boolean {
if (response.status !== code) {
return false;
}
let body = response.data;
if(code === 401) {
body = "Unauthorized request (401): Invalid authentication.";
}
reject(new HttpError(response, body, response.status));
return true;
}
function handleErrorRangeResponse(
reject: AxiosReject,
response: AxiosResponse,
code: string,
returnType: string
): boolean {
let rangeCodeLeft = Number(code[0] + "00");
let rangeCodeRight = Number(code[0] + "99");
if (response.status >= rangeCodeLeft && response.status <= rangeCodeRight) {
const body = ObjectSerializer.deserialize(
response.data,
returnType,
);
reject(new HttpError(response, body, response.status));
return true;
}
return false;
}