Client Configuration

Request Options

You can pass an optional configuration object to any API call to override default behaviors on a per-request basis.

Additional Headers & Query Parameters

Append custom headers or query parameters to specific requests:

1const response = await client.authentication.loginResourceTokenApi(..., {
2 headers: {
3 'X-Custom-Header': 'custom value'
4 },
5 queryParams: {
6 'customQueryParamKey': 'custom query param value'
7 }
8});

Retries

The SDK is instrumented with automatic retries using exponential backoff. A request will be retried as long as it is deemed retryable (e.g., 408 Timeout, 429 Too Many Requests, or 5XX Server Errors) and the attempt count has not exceeded the limit (default: 2).

1const response = await client.authentication.loginResourceTokenApi(..., {
2 maxRetries: 0 // Disable retries for this request
3});

Timeouts

The SDK defaults to a 60-second timeout. Override this using the timeoutInSeconds option:

1const response = await client.authentication.loginResourceTokenApi(..., {
2 timeoutInSeconds: 30
3});

Aborting Requests

You can abort requests at any point by passing in an AbortSignal.

1const controller = new AbortController();
2const response = await client.authentication.loginResourceTokenApi(..., {
3 abortSignal: controller.signal
4});
5
6controller.abort(); // aborts the request

Accessing Raw Response Data

To access the raw response data (including headers), chain the .withRawResponse() method. This returns a promise that resolves to an object containing both the parsed data and the rawResponse.

1const { data, rawResponse } = await client.authentication.loginResourceTokenApi(...).withRawResponse();
2
3console.log(data);
4console.log(rawResponse.headers['X-My-Header']);

Customizing the Fetch Client

If you are running in an unsupported environment or need to intercept network traffic, you can provide a custom fetch implementation when instantiating the client.

1import { MMGClient } from "mobile-money-sdk";
2
3const client = new MMGClient({
4 // ... credentials
5 fetcher: // provide your custom fetch function here
6});