boldsign
Version:
NodeJS client for boldsign
780 lines (672 loc) • 28.8 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,
CreateGroupContactResponse,ErrorResult,GetGroupContactDetails,GroupContactDetails,GroupContactsList,UpdateGroupContact,
} 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 GroupContactsApi {
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 a new Group Contact.
* @param groupContactDetails The group contact details.
* @param options
*/
public async createGroupContact (groupContactDetails?: GroupContactDetails, options: optionsI = {headers: {}}) : Promise<CreateGroupContactResponse> {
groupContactDetails = deserializeIfNeeded(groupContactDetails, "GroupContactDetails");
const localVarPath = this.basePath + '/v1/contactGroups/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;
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
const result = generateFormData(groupContactDetails, GroupContactDetails);
localVarUseFormData = result.localVarUseFormData;
let data = {};
if (localVarUseFormData) {
const formData = toFormData(result.data);
data = formData;
localVarHeaderParams = {
...localVarHeaderParams,
...formData.getHeaders(),
};
} else {
data = ObjectSerializer.serialize(
groupContactDetails,
"GroupContactDetails"
);
}
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<CreateGroupContactResponse>((resolve, reject) => {
axios.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse<CreateGroupContactResponse>(
resolve,
reject,
response,
"CreateGroupContactResponse",
);
}, (error: AxiosError) => {
if (error.response == null) {
reject(error);
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
201,
"CreateGroupContactResponse",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
401,
"ErrorResult",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
400,
"ErrorResult",
)) {
return;
}
reject(error);
});
});
});
}
/**
*
* @summary Deletes a Group Contact.
* @param groupId The group contact id.
* @param options
*/
public async deleteGroupContact (groupId: string, options: optionsI = {headers: {}}) : Promise<returnTypeI> {
const localVarPath = this.basePath + '/v1/contactGroups/delete';
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 'groupId' is not null or undefined
if (groupId === null || groupId === undefined) {
throw new Error('Required parameter groupId was null or undefined when calling deleteGroupContact.');
}
if (groupId !== undefined) {
localVarQueryParameters['groupId'] = ObjectSerializer.serialize(groupId, "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: 'DELETE',
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);
});
});
});
}
/**
*
* @summary Get Summary of the Group Contact.
* @param groupId Group Contact Id.
* @param options
*/
public async getGroupContact (groupId: string, options: optionsI = {headers: {}}) : Promise<GetGroupContactDetails> {
const localVarPath = this.basePath + '/v1/contactGroups/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 'groupId' is not null or undefined
if (groupId === null || groupId === undefined) {
throw new Error('Required parameter groupId was null or undefined when calling getGroupContact.');
}
if (groupId !== undefined) {
localVarQueryParameters['groupId'] = ObjectSerializer.serialize(groupId, "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<GetGroupContactDetails>((resolve, reject) => {
axios.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse<GetGroupContactDetails>(
resolve,
reject,
response,
"GetGroupContactDetails",
);
}, (error: AxiosError) => {
if (error.response == null) {
reject(error);
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
200,
"GetGroupContactDetails",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
401,
"ErrorResult",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
403,
"ErrorResult",
)) {
return;
}
reject(error);
});
});
});
}
/**
*
* @summary List Group Contacts.
* @param page Page index specified in get user group contact list request. Default value is 1.
* @param pageSize Page size specified in get user group contact list request. Default value is 10.
* @param searchKey Group Contacts can be listed by the search based on the Name or Email
* @param contactType Group Contact type whether the contact is my contacts or all contacts. Default value is AllContacts.
* @param directories Group Contacts can be listed by the search based on the directories
* @param options
*/
public async groupContactList (page: number, pageSize?: number, searchKey?: string, contactType?: 'MyContacts' | 'AllContacts', directories?: Array<string>, options: optionsI = {headers: {}}) : Promise<GroupContactsList> {
const localVarPath = this.basePath + '/v1/contactGroups/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 groupContactList.');
}
if (pageSize !== undefined) {
localVarQueryParameters['PageSize'] = ObjectSerializer.serialize(pageSize, "number");
}
if (page !== undefined) {
localVarQueryParameters['Page'] = ObjectSerializer.serialize(page, "number");
}
if (searchKey !== undefined) {
localVarQueryParameters['SearchKey'] = ObjectSerializer.serialize(searchKey, "string");
}
if (contactType !== undefined) {
localVarQueryParameters['ContactType'] = ObjectSerializer.serialize(contactType, "'MyContacts' | 'AllContacts'");
}
if (directories !== undefined) {
localVarQueryParameters['Directories'] = ObjectSerializer.serialize(directories, "Array<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<GroupContactsList>((resolve, reject) => {
axios.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse<GroupContactsList>(
resolve,
reject,
response,
"GroupContactsList",
);
}, (error: AxiosError) => {
if (error.response == null) {
reject(error);
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
200,
"GroupContactsList",
)) {
return;
}
if (handleErrorCodeResponse(
reject,
error.response,
401,
"ErrorResult",
)) {
return;
}
reject(error);
});
});
});
}
/**
*
* @summary Update the Group Contact.
* @param groupId The group contact ID.
* @param updateGroupContact The group contact details.
* @param options
*/
public async updateGroupContact (groupId: string, updateGroupContact: UpdateGroupContact, options: optionsI = {headers: {}}) : Promise<returnTypeI> {
updateGroupContact = deserializeIfNeeded(updateGroupContact, "UpdateGroupContact");
const localVarPath = this.basePath + '/v1/contactGroups/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 'groupId' is not null or undefined
if (groupId === null || groupId === undefined) {
throw new Error('Required parameter groupId was null or undefined when calling updateGroupContact.');
}
// verify required parameter 'updateGroupContact' is not null or undefined
if (updateGroupContact === null || updateGroupContact === undefined) {
throw new Error('Required parameter updateGroupContact was null or undefined when calling updateGroupContact.');
}
if (groupId !== undefined) {
localVarQueryParameters['groupId'] = ObjectSerializer.serialize(groupId, "string");
}
(<any>Object).assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
const result = generateFormData(updateGroupContact, UpdateGroupContact);
localVarUseFormData = result.localVarUseFormData;
let data = {};
if (localVarUseFormData) {
const formData = toFormData(result.data);
data = formData;
localVarHeaderParams = {
...localVarHeaderParams,
...formData.getHeaders(),
};
} else {
data = ObjectSerializer.serialize(
updateGroupContact,
"UpdateGroupContact"
);
}
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,
400,
"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;
}