UNPKG

mnotify-ts-sdk

Version:

Modern, zero-dependency TypeScript SDK for mNotify BMS API - Type-safe SMS, contacts, and account management with Railway-Oriented Programming

131 lines (130 loc) 4.2 kB
import type { HttpClient } from "../client/HttpClient"; import type { Result } from "../types/Result"; import { MNotifyError } from "../errors/MNotifyError"; /** * Account balance response */ export interface BalanceResponse { balance: number; currency: string; } /** * Sender ID information */ export interface SenderId { id: string; name: string; status: "approved" | "pending" | "rejected"; created_at: string; } export interface SenderIdStatus { status: string; message?: string; sender_name?: string; approval_status?: string; } /** * Service for managing account operations with mNotify API */ export declare class AccountService { private readonly client; constructor(client: HttpClient); private annotate; /** * Retrieves current account balance (railway-oriented programming) * @returns Result containing balance information or error * * @example * ```typescript * const result = await accountService.getBalanceSafe(); * result.match({ * ok: (balance) => console.log(`Balance: ${balance.balance} ${balance.currency}`), * err: (error) => console.error('Failed to get balance:', error) * }); * ``` */ getBalanceSafe(): Promise<Result<BalanceResponse, MNotifyError>>; /** * Retrieves current account balance (throws on error - legacy API) * @returns Account balance information * @throws {MNotifyError} On API failure * * @example * ```typescript * const balance = await accountService.getBalance(); * console.log(`Balance: ${balance.balance} ${balance.currency}`); * ``` */ getBalance(): Promise<BalanceResponse>; /** * Retrieves list of registered sender IDs (railway-oriented programming) * @returns Result containing array of sender IDs or error * * @example * ```typescript * const result = await accountService.getSenderIdsSafe(); * if (result.isOk()) { * console.log('Available sender IDs:', result.value); * } * ``` */ getSenderIdsSafe(): Promise<Result<SenderId[], MNotifyError>>; /** * Retrieves list of registered sender IDs (throws on error - legacy API) * @returns Array of sender IDs * @throws {MNotifyError} On API failure * * @example * ```typescript * const senderIds = await accountService.getSenderIds(); * console.log('Available sender IDs:', senderIds); * ``` */ getSenderIds(): Promise<SenderId[]>; /** * Registers a new sender ID (railway-oriented programming) * @param name - Sender ID name to register * @returns Result containing registration response or error * * @example * ```typescript * const result = await accountService.registerSenderIdSafe('MyApp'); * result.match({ * ok: (res) => console.log('Sender ID registered:', res), * err: (error) => console.error('Registration failed:', error) * }); * ``` */ registerSenderIdSafe(name: string, purpose?: string[]): Promise<Result<{ status: string; message: string; }, MNotifyError>>; /** * Registers a new sender ID (throws on error - legacy API) * @param name - Sender ID name to register * @returns Registration response * @throws {MNotifyError} On API failure * * @example * ```typescript * const result = await accountService.registerSenderId('MyApp'); * console.log('Sender ID registered:', result); * ``` */ registerSenderId(name: string, purpose?: string[]): Promise<{ status: string; message: string; }>; /** * Checks sender ID approval status (railway-oriented programming) * @param name - Sender ID name * @returns Result containing sender status response or error */ checkSenderIdStatusSafe(name: string): Promise<Result<SenderIdStatus, MNotifyError>>; /** * Checks sender ID approval status (throws on error - legacy API) * @param name - Sender ID name * @returns Sender status response */ checkSenderIdStatus(name: string): Promise<SenderIdStatus>; }