boldsign
Version:
NodeJS client for boldsign
507 lines • 25.3 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.GroupContactsApi = void 0;
const axios_1 = __importDefault(require("axios"));
const model_1 = require("../model");
const _1 = require("./");
let defaultBasePath = 'https://api.boldsign.com';
class GroupContactsApi {
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);
}
createGroupContact(groupContactDetails_1) {
return __awaiter(this, arguments, void 0, function* (groupContactDetails, options = { headers: {} }) {
groupContactDetails = deserializeIfNeeded(groupContactDetails, "GroupContactDetails");
const localVarPath = this.basePath + '/v1/contactGroups/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)(groupContactDetails, model_1.GroupContactDetails);
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(groupContactDetails, "GroupContactDetails");
}
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, "CreateGroupContactResponse");
}, (error) => {
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);
});
});
});
});
}
deleteGroupContact(groupId_1) {
return __awaiter(this, arguments, void 0, function* (groupId, options = { headers: {} }) {
const localVarPath = this.basePath + '/v1/contactGroups/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 (groupId === null || groupId === undefined) {
throw new Error('Required parameter groupId was null or undefined when calling deleteGroupContact.');
}
if (groupId !== undefined) {
localVarQueryParameters['groupId'] = model_1.ObjectSerializer.serialize(groupId, "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);
});
});
});
});
}
getGroupContact(groupId_1) {
return __awaiter(this, arguments, void 0, function* (groupId, options = { headers: {} }) {
const localVarPath = this.basePath + '/v1/contactGroups/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 (groupId === null || groupId === undefined) {
throw new Error('Required parameter groupId was null or undefined when calling getGroupContact.');
}
if (groupId !== undefined) {
localVarQueryParameters['groupId'] = model_1.ObjectSerializer.serialize(groupId, "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, "GetGroupContactDetails");
}, (error) => {
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);
});
});
});
});
}
groupContactList(page_1, pageSize_1, searchKey_1, contactType_1, directories_1) {
return __awaiter(this, arguments, void 0, function* (page, pageSize, searchKey, contactType, directories, options = { headers: {} }) {
const localVarPath = this.basePath + '/v1/contactGroups/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 groupContactList.');
}
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'");
}
if (directories !== undefined) {
localVarQueryParameters['Directories'] = model_1.ObjectSerializer.serialize(directories, "Array<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, "GroupContactsList");
}, (error) => {
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);
});
});
});
});
}
updateGroupContact(groupId_1, updateGroupContact_1) {
return __awaiter(this, arguments, void 0, function* (groupId, updateGroupContact, options = { headers: {} }) {
updateGroupContact = deserializeIfNeeded(updateGroupContact, "UpdateGroupContact");
const localVarPath = this.basePath + '/v1/contactGroups/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 (groupId === null || groupId === undefined) {
throw new Error('Required parameter groupId was null or undefined when calling updateGroupContact.');
}
if (updateGroupContact === null || updateGroupContact === undefined) {
throw new Error('Required parameter updateGroupContact was null or undefined when calling updateGroupContact.');
}
if (groupId !== undefined) {
localVarQueryParameters['groupId'] = model_1.ObjectSerializer.serialize(groupId, "string");
}
Object.assign(localVarHeaderParams, options.headers);
let localVarUseFormData = false;
const result = (0, _1.generateFormData)(updateGroupContact, model_1.UpdateGroupContact);
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(updateGroupContact, "UpdateGroupContact");
}
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.GroupContactsApi = GroupContactsApi;
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=groupContactsApi.js.map