@sonatel-os/juf
Version:
The community SDK for Orange Money, SMS, Email & Sonatel APIs on the Orange Developer Platform.
74 lines (71 loc) • 2.79 kB
text/typescript
import * as axios from 'axios';
import { C as Cache$1 } from '../cache-Bxhh3lYR.cjs';
type Cache = Cache$1;
/**
* @class Authentication
* @classdesc Provides methods to handle authentication and token management with the Sonatel API Platform.
* Utilizes caching to store tokens and optimizes API requests by reducing unnecessary network calls.
*
* Supports dependency injection for testability — pass dependencies via constructor,
* or use the {@link Authentication.init} factory for default behavior.
*
* @example
* // Default usage (backward compatible)
* const authentication = Authentication.init();
* const { access_token } = await authentication.debug();
*
* @example
* // With dependency injection (for testing)
* const authentication = new Authentication({ config, cache: mockCache, client: mockAxios, logger: mockLogger });
*
* @typedef {import('../core/cache.js').default} Cache
*/
declare class Authentication {
/**
* Factory method to initialize Authentication with default dependencies.
* @memberof Service\Authentication
* @method init
* @returns {Authentication} An initialized instance of Authentication.
*/
static init(): Authentication;
/**
* Creates an Authentication instance with injectable dependencies.
*
* @param {object} deps - Dependencies for the authentication service.
* @param {object} deps.config - Apigee configuration (client_id, client_secret, urls, etc.).
* @param {Cache} deps.cache - Cache instance for token storage.
* @param {import('axios').AxiosInstance} deps.client - HTTP client instance.
* @param {object} deps.logger - Logger instance with error/warn/info/debug methods.
*/
constructor({ config, cache, client, logger }: {
config: object;
cache: Cache;
client: axios.AxiosInstance;
logger: object;
});
/**
* Authenticates against the Sonatel API Platform using the client credentials flow.
* Caches the access token to reduce redundant authentication calls.
*
* @async
* @method debug
* @memberof Service\Authentication
* @returns {Promise<{ access_token: string, expires_in: number, refresh_expires_in: number, token_type: string, notbefore_policy: number, session_state: string }>}
* @throws {AuthenticationError} When authentication fails.
*
* @example
* authentication.debug()
* .then(console.log)
* .catch(({ message }) => console.log(`Failed: ${message}`))
*/
debug(): Promise<{
access_token: string;
expires_in: number;
refresh_expires_in: number;
token_type: string;
notbefore_policy: number;
session_state: string;
}>;
#private;
}
export { Authentication };