verimor-api-sdk
Version:
A NodeJS SDK for the Verimor API
97 lines • 4.22 kB
JavaScript
;
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.IysApi = void 0;
const base_api_1 = require("./base-api");
const error_response_1 = require("../models/error-response");
/**
* IysApi class provides methods for IYS integration.
*/
class IysApi extends base_api_1.BaseApi {
/**
* Creates an instance of IysApi.
* @param username - The API username.
* @param password - The API password.
* @param proxyConfig - Optional proxy configuration.
*/
constructor(username, password, proxyConfig) {
super(username, password, proxyConfig);
}
/**
* Sends IYS consents.
* @param sourceAddr - The sender ID.
* @param consents - Array of IysConsent objects.
* @returns Promise resolving to a campaign ID.
* @throws ErrorResponse if the API call fails.
*/
sendIysConsents(sourceAddr, consents) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const payload = this.withCredentials({
source_addr: sourceAddr,
consents: consents,
});
const response = yield this.apiClient.post('/iys_consents.json', payload);
return response.data;
}
catch (error) {
throw new error_response_1.ErrorResponse(((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
}
});
}
/**
* Fetches IYS campaigns.
* @param offset - Pagination offset.
* @param limit - Number of records to retrieve.
* @param source - Filter by source (e.g., 'iys', 'api').
* @returns Promise resolving to an object containing total and records.
* @throws ErrorResponse if the API call fails.
*/
getIysCampaigns(offset = 0, limit = 100, source) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const params = this.withCredentialsParams({ offset, limit, source });
const response = yield this.apiClient.get('/iys/campaigns', { params });
return response.data;
}
catch (error) {
throw new error_response_1.ErrorResponse(((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
}
});
}
/**
* Fetches IYS consent reports for a campaign.
* @param campaignId - The IYS campaign ID.
* @param offset - Pagination offset.
* @param limit - Number of records to retrieve.
* @returns Promise resolving to consent report data.
* @throws ErrorResponse if the API call fails.
*/
getIysConsentReports(campaignId, offset = 0, limit = 100) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
const params = this.withCredentialsParams({ offset, limit });
const response = yield this.apiClient.get(`/iys/campaigns/${campaignId}/consents`, {
params,
});
return response.data;
}
catch (error) {
throw new error_response_1.ErrorResponse(((_a = error.response) === null || _a === void 0 ? void 0 : _a.data) || error.message);
}
});
}
}
exports.IysApi = IysApi;
//# sourceMappingURL=iys-api.js.map