@sonatel-os/juf
Version:
The community SDK for Orange Money, SMS, Email & Sonatel APIs on the Orange Developer Platform.
116 lines (113 loc) • 4.49 kB
TypeScript
import * as axios from 'axios';
import { Authentication } from './auth/index.js';
/**
* @class Communication
* @classdesc Provides methods for sending emails and SMS through the Apigee API.
*
* Supports dependency injection for testability — pass dependencies via constructor,
* or use the {@link Communication.init} factory for default behavior.
*
* @example
* // Default usage (backward compatible)
* const commService = Communication.init();
*
* @example
* // With dependency injection (for testing)
* const commService = new Communication({ authService: mockAuth, client: mockAxios, logger: mockLogger });
*/
declare class Communication {
/**
* Factory method to initialize Communication with default dependencies.
* @method init
* @memberof Service\Communication
* @param {object} [deps] - Optional shared dependencies.
* @param {Authentication} [deps.authService] - Shared auth instance (avoids duplicate token fetches).
* @returns {Communication} An initialized instance of Communication.
*/
static init({ authService }?: {
authService?: Authentication | undefined;
} | undefined): Communication;
/**
* Creates a Communication instance with injectable dependencies.
*
* @param {object} deps - Dependencies for the communication service.
* @param {Authentication} deps.authService - Authentication service instance.
* @param {import('axios').AxiosInstance} deps.client - HTTP client instance.
* @param {object} deps.logger - Logger instance with error/warn/info/debug methods.
*/
constructor({ authService, client, logger }: {
authService: Authentication;
client: axios.AxiosInstance;
logger: object;
});
/**
* Sends an email through the Apigee API.
*
* @async
* @method sendEmail
* @memberof Service\Communication
* @param {object} emailParams - Parameters for the email to be sent.
* @param {string} emailParams.subject - The subject of the email.
* @param {string} emailParams.to - The email address of the recipient.
* @param {string} emailParams.from - The email address of the sender.
* @param {string} emailParams.body - The plaintext body of the email.
* @param {boolean} [emailParams.html] - Whether the body is HTML (optional).
* @returns {Promise<{ id: string, status: string }>} The response from the Apigee API.
* @throws {import('../core/errors.js').ValidationError} When input validation fails.
* @throws {import('../core/errors.js').ExternalServiceError} When the API request fails.
*
* @example
* communication.sendEmail({
* subject: 'Hello!',
* to: 'recipient@example.com',
* from: 'sender@example.com',
* body: '<p>This is a test email.</p>',
* html: true
* });
*/
sendEmail({ subject, to, from, body, html }: {
subject: string;
to: string;
from: string;
body: string;
html?: boolean | undefined;
}): Promise<{
id: string;
status: string;
}>;
/**
* Sends an SMS through the Apigee API.
*
* @async
* @method sendSMS
* @memberof Service\Communication
* @param {object} smsParams - Parameters for the SMS to be sent.
* @param {string} smsParams.body - The message body of the SMS.
* @param {boolean} [smsParams.confidential=true] - Whether the message is confidential.
* @param {string} [smsParams.scheduledFor] - Scheduled time (ISO 8601 format).
* @param {string} smsParams.senderName - The name of the sender.
* @param {string} smsParams.to - The phone number of the recipient.
* @returns {Promise<{ id: string, status: string }>} The response from the Apigee API.
* @throws {import('../core/errors.js').ValidationError} When input validation fails.
* @throws {import('../core/errors.js').ExternalServiceError} When the API request fails.
*
* @example
* communication.sendSMS({
* body: 'This is a test SMS.',
* to: '+1234567890',
* senderName: 'MyApp'
* });
*/
sendSMS({ body, confidential, scheduledFor, senderName, to }: {
body: string;
confidential?: boolean | undefined;
scheduledFor?: string | undefined;
senderName: string;
to: string;
}): Promise<{
id: string;
status: string;
}>;
#private;
}
export { Communication as C };