UNPKG

@crediblex.io/fineract-api-client

Version:
82 lines 3.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FineractSmeApi = void 0; const errors_1 = require("../types/errors"); /** * API client for Fineract SME related operations. * It uses the HttpClient for making requests. */ class FineractSmeApi { constructor(httpClient) { this.httpClient = httpClient; } /** * Creates a new sme in Fineract. * Corresponds to the POST /create endpoint in your `clients.ts`. * * @param smeData The data for the new sme. * @returns A promise that resolves to the creation response or rejects with an error. * @remarks SME is referred as client in fineract system */ async create(smeData) { try { const apiPath = "/fineract-provider/api/v1/clients"; const response = await this.httpClient.post(apiPath, smeData); return response.data; } catch (rawError) { const errorPayload = rawError; const message = errorPayload?.message || errorPayload?.error || "Fineract API request failed"; throw new errors_1.FineractApiError(message, errorPayload?.statusCode, errorPayload?.details, errorPayload?.error); } } /** * Retrieves details for a specific client from Fineract. * Corresponds to the GET /details/:clientId endpoint in your `clients.ts`. * * @param clientId The ID of the client to retrieve. * @returns A promise that resolves to the client details or rejects with an error. * @remarks The actual API path for retrieving client details (e.g., `/clients/${clientId}`) * needs to be verified from your Fineract API documentation or the SDK. */ async getDetails(clientId) { try { const apiPath = `/fineract-provider/api/v1/clients/${clientId}`; // Example path const response = await this.httpClient.get(apiPath); return response.data; } catch (rawError) { const errorPayload = rawError; const message = errorPayload?.message || errorPayload?.error || "Fineract API request failed"; throw new errors_1.FineractApiError(message, errorPayload?.statusCode, errorPayload?.details, errorPayload?.error); } } /** * Retrieves details for a specific client from Fineract using external ID. * Corresponds to the GET /v1/clients/external-id/{externalId} endpoint. * * @param externalId The external ID of the client to retrieve. * @returns A promise that resolves to the client details or rejects with an error. * @remarks SME is referred as client in fineract system */ async getDetailsByExternalId(externalId) { try { const apiPath = `/fineract-provider/api/v1/clients/external-id/${externalId}`; const response = await this.httpClient.get(apiPath); return response.data; } catch (rawError) { const errorPayload = rawError; const message = errorPayload?.message || errorPayload?.error || "Fineract API request failed"; throw new errors_1.FineractApiError(message, errorPayload?.statusCode, errorPayload?.details, errorPayload?.error); } } } exports.FineractSmeApi = FineractSmeApi; //# sourceMappingURL=fineract-sme-api.js.map