boldsign
Version:
NodeJS client for boldsign
501 lines • 24.5 kB
JavaScript
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContactsApi = void 0;
const axios_1 = __importDefault(require("axios"));
const model_1 = require("../model");
const _1 = require("./");
let defaultBasePath = 'https://api.boldsign.com';
class ContactsApi {
constructor(basePath) {
this._basePath = defaultBasePath;
this._defaultHeaders = { 'User-Agent': _1.USER_AGENT };
this._useQuerystring = true;
this.authentications = {
'default': new model_1.VoidAuth(),
'Bearer': new model_1.ApiKeyAuth('header', 'Authorization'),
'X-API-KEY': new model_1.ApiKeyAuth('header', 'X-API-KEY'),
};
this.interceptors = [];
if (basePath) {
this.basePath = basePath;
}
}
set useQuerystring(value) {
this._useQuerystring = value;
}
set basePath(basePath) {
this._basePath = basePath;
}
set defaultHeaders(defaultHeaders) {
this._defaultHeaders = Object.assign(Object.assign({}, defaultHeaders), { "User-Agent": _1.USER_AGENT });
}
get defaultHeaders() {
return this._defaultHeaders;
}
get basePath() {
return this._basePath;
}
setDefaultAuthentication(auth) {
this.authentications.default = auth;
}
setApiKey(apikey) {
this.authentications["X-API-KEY"].apiKey = apikey;
}
setAccessToken(accessToken) {
this.authentications["Bearer"].apiKey = 'bearer ' + accessToken;
}
addInterceptor(interceptor) {
this.interceptors.push(interceptor);
}
contactUserList(page_1, pageSize_1, searchKey_1, contactType_1) {
return __awaiter(this, arguments, void 0, function* (page, pageSize, searchKey, contactType, options = { headers: {} }) {
const localVarPath = this.basePath + '/v1/contacts/list';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this._defaultHeaders);
const produces = ['application/json'];
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams['content-type'] = 'application/json';
}
else {
localVarHeaderParams['content-type'] = produces.join(',');
}
let localVarFormParams = {};
let localVarBodyParams = undefined;
if (page === null || page === undefined) {
throw new Error('Required parameter page was null or undefined when calling contactUserList.');
}
if (pageSize !== undefined) {
localVarQueryParameters['PageSize'] = model_1.ObjectSerializer.serialize(pageSize, "number");
}
if (page !== undefined) {
localVarQueryParameters['Page'] = model_1.ObjectSerializer.serialize(page, "number");
}
if (searchKey !== undefined) {
localVarQueryParameters['SearchKey'] = model_1.ObjectSerializer.serialize(searchKey, "string");
}
if (contactType !== undefined) {
localVarQueryParameters['ContactType'] = model_1.ObjectSerializer.serialize(contactType, "'MyContacts' | 'AllContacts'");
}
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let data = {};
if (localVarUseFormData) {
const formData = (0, _1.toFormData)(localVarFormParams);
data = formData;
localVarHeaderParams = Object.assign(Object.assign({}, localVarHeaderParams), formData.getHeaders());
}
let localVarRequestOptions = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
paramsSerializer: this._useQuerystring ? _1.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((resolve, reject) => {
axios_1.default.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse(resolve, reject, response, "ContactsList");
}, (error) => {
if (error.response == null) {
reject(error);
return;
}
if (handleErrorCodeResponse(reject, error.response, 200, "ContactsList")) {
return;
}
if (handleErrorCodeResponse(reject, error.response, 401, "ErrorResult")) {
return;
}
if (handleErrorCodeResponse(reject, error.response, 400, "ErrorResult")) {
return;
}
reject(error);
});
});
});
});
}
createContact(contactDetails_1) {
return __awaiter(this, arguments, void 0, function* (contactDetails, options = { headers: {} }) {
contactDetails = deserializeIfNeeded(contactDetails, "Array<ContactDetails>");
const localVarPath = this.basePath + '/v1/contacts/create';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this._defaultHeaders);
const produces = ['application/json'];
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams['content-type'] = 'application/json';
}
else {
localVarHeaderParams['content-type'] = produces.join(',');
}
let localVarFormParams = {};
let localVarBodyParams = undefined;
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
const result = (0, _1.generateFormData)(contactDetails, (Array));
localVarUseFormData = result.localVarUseFormData;
let data = {};
if (localVarUseFormData) {
const formData = (0, _1.toFormData)(result.data);
data = formData;
localVarHeaderParams = Object.assign(Object.assign({}, localVarHeaderParams), formData.getHeaders());
}
else {
data = model_1.ObjectSerializer.serialize(contactDetails, "Array<ContactDetails>");
}
let localVarRequestOptions = {
method: 'POST',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
paramsSerializer: this._useQuerystring ? _1.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((resolve, reject) => {
axios_1.default.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse(resolve, reject, response, "CreateContactResponse");
}, (error) => {
if (error.response == null) {
reject(error);
return;
}
if (handleErrorCodeResponse(reject, error.response, 201, "CreateContactResponse")) {
return;
}
if (handleErrorCodeResponse(reject, error.response, 401, "ErrorResult")) {
return;
}
if (handleErrorCodeResponse(reject, error.response, 400, "ErrorResult")) {
return;
}
reject(error);
});
});
});
});
}
deleteContacts(id_1) {
return __awaiter(this, arguments, void 0, function* (id, options = { headers: {} }) {
const localVarPath = this.basePath + '/v1/contacts/delete';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this._defaultHeaders);
const produces = ['application/json'];
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams['content-type'] = 'application/json';
}
else {
localVarHeaderParams['content-type'] = produces.join(',');
}
let localVarFormParams = {};
let localVarBodyParams = undefined;
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling deleteContacts.');
}
if (id !== undefined) {
localVarQueryParameters['id'] = model_1.ObjectSerializer.serialize(id, "string");
}
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let data = {};
if (localVarUseFormData) {
const formData = (0, _1.toFormData)(localVarFormParams);
data = formData;
localVarHeaderParams = Object.assign(Object.assign({}, localVarHeaderParams), formData.getHeaders());
}
let localVarRequestOptions = {
method: 'DELETE',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
paramsSerializer: this._useQuerystring ? _1.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((resolve, reject) => {
axios_1.default.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse(resolve, reject, response);
}, (error) => {
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);
});
});
});
});
}
getContact(id_1) {
return __awaiter(this, arguments, void 0, function* (id, options = { headers: {} }) {
const localVarPath = this.basePath + '/v1/contacts/get';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this._defaultHeaders);
const produces = ['application/json'];
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams['content-type'] = 'application/json';
}
else {
localVarHeaderParams['content-type'] = produces.join(',');
}
let localVarFormParams = {};
let localVarBodyParams = undefined;
if (id === null || id === undefined) {
throw new Error('Required parameter id was null or undefined when calling getContact.');
}
if (id !== undefined) {
localVarQueryParameters['id'] = model_1.ObjectSerializer.serialize(id, "string");
}
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
let data = {};
if (localVarUseFormData) {
const formData = (0, _1.toFormData)(localVarFormParams);
data = formData;
localVarHeaderParams = Object.assign(Object.assign({}, localVarHeaderParams), formData.getHeaders());
}
let localVarRequestOptions = {
method: 'GET',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
paramsSerializer: this._useQuerystring ? _1.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((resolve, reject) => {
axios_1.default.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse(resolve, reject, response, "ContactsDetails");
}, (error) => {
if (error.response == null) {
reject(error);
return;
}
if (handleErrorCodeResponse(reject, error.response, 200, "ContactsDetails")) {
return;
}
if (handleErrorCodeResponse(reject, error.response, 401, "ErrorResult")) {
return;
}
if (handleErrorCodeResponse(reject, error.response, 403, "ErrorResult")) {
return;
}
reject(error);
});
});
});
});
}
updateContact(id_1, contactDetails_1) {
return __awaiter(this, arguments, void 0, function* (id, contactDetails, options = { headers: {} }) {
contactDetails = deserializeIfNeeded(contactDetails, "ContactDetails");
const localVarPath = this.basePath + '/v1/contacts/update';
let localVarQueryParameters = {};
let localVarHeaderParams = Object.assign({}, this._defaultHeaders);
const produces = ['application/json'];
if (produces.indexOf('application/json') >= 0) {
localVarHeaderParams['content-type'] = 'application/json';
}
else {
localVarHeaderParams['content-type'] = produces.join(',');
}
let localVarFormParams = {};
let localVarBodyParams = undefined;
if (id !== undefined) {
localVarQueryParameters['id'] = model_1.ObjectSerializer.serialize(id, "string");
}
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
const result = (0, _1.generateFormData)(contactDetails, model_1.ContactDetails);
localVarUseFormData = result.localVarUseFormData;
let data = {};
if (localVarUseFormData) {
const formData = (0, _1.toFormData)(result.data);
data = formData;
localVarHeaderParams = Object.assign(Object.assign({}, localVarHeaderParams), formData.getHeaders());
}
else {
data = model_1.ObjectSerializer.serialize(contactDetails, "ContactDetails");
}
let localVarRequestOptions = {
method: 'PUT',
params: localVarQueryParameters,
headers: localVarHeaderParams,
url: localVarPath,
paramsSerializer: this._useQuerystring ? _1.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((resolve, reject) => {
axios_1.default.request(localVarRequestOptions)
.then((response) => {
handleSuccessfulResponse(resolve, reject, response);
}, (error) => {
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);
});
});
});
});
}
}
exports.ContactsApi = ContactsApi;
function deserializeIfNeeded(obj, classname) {
if (obj !== null && obj !== undefined && obj.constructor.name !== classname) {
return model_1.ObjectSerializer.deserialize(obj, classname);
}
return obj;
}
function handleSuccessfulResponse(resolve, reject, response, returnType) {
let body = response.data;
if (response.status &&
response.status >= 200 &&
response.status <= 299) {
if (returnType) {
body = model_1.ObjectSerializer.deserialize(body, returnType);
}
resolve(body);
}
else {
reject(new _1.HttpError(response, body, response.status));
}
}
function handleErrorCodeResponse(reject, response, code, returnType) {
if (response.status !== code) {
return false;
}
let body = response.data;
if (code === 401) {
body = "Unauthorized request (401): Invalid authentication.";
}
reject(new _1.HttpError(response, body, response.status));
return true;
}
function handleErrorRangeResponse(reject, response, code, returnType) {
let rangeCodeLeft = Number(code[0] + "00");
let rangeCodeRight = Number(code[0] + "99");
if (response.status >= rangeCodeLeft && response.status <= rangeCodeRight) {
const body = model_1.ObjectSerializer.deserialize(response.data, returnType);
reject(new _1.HttpError(response, body, response.status));
return true;
}
return false;
}
//# sourceMappingURL=contactsApi.js.map