akua-sdk
Version:
TypeScript SDK for Akua Acquiring Processor
72 lines (71 loc) • 2.67 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebhookService = void 0;
const mapper_1 = require("../helpers/mapper");
/**
* Service responsible for managing webhook configurations in the Akua API.
* @class WebhookService
*/
class WebhookService {
httpClient;
/**
* Creates an instance of WebhookService.
* @param {HttpClient} httpClient - The HTTP client instance used for making API requests.
*/
constructor(httpClient) {
this.httpClient = httpClient;
}
/**
* Creates a new webhook configuration.
* @param createWebhookRequest - The request object containing the webhook configuration details.
* @returns {Promise<ApiResponse<WebhookDTO>>} A promise that resolves to the created webhook configuration.
* @example
* // Create a new webhook configuration
* await webhookService.create({
* url: 'https://example.com/webhook',
* events: [AkuaTypes.Enums.EventType.PAYMENT_AUTHORIZATION_PROCESSED],
* description: 'Webhook for payment events',
* rate_limit: 1,
* });
*/
async create(createWebhookRequest) {
const response = await this.httpClient.post('/v1/webhooks', createWebhookRequest);
const mappedData = mapper_1.Mapper.mapToWebhookDTO(response.data);
return {
...response,
data: mappedData,
};
}
/**
* Retrieves all webhook configurations.
* @returns {Promise<ApiResponse<WebhookDTO[]>>} A promise that resolves to an array of webhook configurations.
* @example
* // Get all webhook configurations
* await webhookService.get();
*/
async get() {
const response = await this.httpClient.get('/v1/webhooks');
const mappedData = response.data.data.map((webhook) => mapper_1.Mapper.mapToWebhookDTO(webhook));
return {
...response,
data: mappedData,
};
}
/**
* Retrieves a webhook configuration by its ID.
* @param webhookId - The ID of the webhook configuration to retrieve.
* @returns {Promise<ApiResponse<WebhookSecretDTO>>} A promise that resolves to the webhook configuration.
* @example
* // Get a webhook configuration by ID
* await webhookService.getSecret('webhook_123');
*/
async getSecret(webhookId) {
const response = await this.httpClient.get(`/v1/webhooks/${webhookId}/secrets`);
const mappedData = mapper_1.Mapper.mapToWebhookSecretDTO(response.data);
return {
...response,
data: mappedData,
};
}
}
exports.WebhookService = WebhookService;