/** * @module * Msegat SMS gateway transport (Saudi Arabia). * * Shapes follow the official Postman collection * ([MSEGAT Communication Platform API](https://documenter.getpostman.com/view/39158411/2sBY4LT3EY)): * - `POST /gw/sendsms.php` — JSON send (`code` `"1"` / `"M0000"`) * - `GET /gw/Credits.php` — balance / credential check * - `POST /gw/sendOTPCode.php` / `verifyOTPCode.php` — vendor OTP helpers * * Sently-first: wire into {@link createSmsSender}; OTP stays on this class. * * @example * ```ts * import { createSmsSender } from "sently/sms"; * import { MsegatTransport } from "sently/transports/msegat"; * * const msegat = new MsegatTransport({ * userName: process.env.MSEGAT_USERNAME!, * apiKey: process.env.MSEGAT_API_KEY!, * sender: "MyBrand", * }); * const sms = createSmsSender({ transport: msegat }); * * await sms.send({ to: "+9665xxxxxxxx", body: "Hello" }); * const otp = await msegat.sendOtp({ to: "+9665xxxxxxxx", lang: "En" }); * await msegat.verifyOtp({ id: otp.id, code: "1234", lang: "En" }); * ``` */ import { SentlyError, type SentlyErrorCode } from "../core/errors.js"; import type { SmsOptions, SmsSendResult, SmsTransport } from "../core/sms-types.js"; import type { VerifyResult } from "../core/types.js"; /** Msegat SMS API configuration. */ export interface MsegatConfig { /** Msegat account username. */ userName: string; /** Msegat API key. */ apiKey: string; /** Pre-approved sender name (use `auth-mseg` for free OTP tests). */ sender: string; } /** Options for {@link MsegatTransport.sendOtp}. */ export interface MsegatSendOtpOptions { /** Recipient phone number (E.164 or international digits). */ to: string; /** Sender ID override; defaults to transport `sender`. */ from?: string; /** * Message language for header + body (`Ar` or `En`). * Postman: "lang : Ar or En in header". Defaults to `"En"`. */ lang?: "Ar" | "En"; } /** Result of a successful {@link MsegatTransport.sendOtp} call. */ export interface MsegatOtpSendResult { /** OTP session id required by {@link MsegatTransport.verifyOtp}. */ id: string; /** Recipient phone number as passed in. */ to: string; /** Delivery status (`"accepted"` on success). */ status: string; /** Raw response body text. */ response: string; /** Provider identifier. */ provider: "msegat"; } /** Options for {@link MsegatTransport.verifyOtp}. */ export interface MsegatVerifyOtpOptions { /** OTP session id from {@link MsegatOtpSendResult.id}. */ id: string | number; /** Code the user entered. */ code: string; /** Sender ID override; defaults to transport `sender`. */ from?: string; /** Message language (`Ar` or `En`). Defaults to `"En"`. */ lang?: "Ar" | "En"; } /** Result of a successful {@link MsegatTransport.verifyOtp} call. */ export interface MsegatOtpVerifyResult { /** Always `true` when the call resolves (failures throw). */ ok: true; /** Provider message when present. */ message: string; /** Raw response body text. */ response: string; /** Provider identifier. */ provider: "msegat"; } /** Error thrown when the Msegat SMS API reports a failure. */ export declare class MsegatError extends SentlyError { readonly statusCode: number; readonly apiError: unknown; /** Creates a Msegat SMS API error with status code and response payload. */ constructor(message: string, statusCode: number, apiError: unknown, sentlyCode?: SentlyErrorCode, /** Msegat response `code` when present (e.g. `"1020"`, `"M0002"`). */ providerCode?: string); } /** * Msegat SMS transport via JSON `sendsms.php` + Credits-based `verify()`, * with provider-specific OTP helpers. */ export declare class MsegatTransport implements SmsTransport { readonly provider = "msegat"; private readonly userName; private readonly apiKey; private readonly sender; /** Creates an Msegat SMS transport. */ constructor(config: MsegatConfig); /** * Sends an SMS via `POST /gw/sendsms.php` * (JSON: `userName`, `apiKey`, `numbers`, `userSender`, `msg`). */ send(options: SmsOptions): Promise; /** * Vendor extra: send a provider-generated OTP via `sendOTPCode.php`. * Not part of {@link SmsTransport} — call on {@link MsegatTransport} directly. * Keep the returned {@link MsegatOtpSendResult.id} for {@link verifyOtp}. */ sendOtp(options: MsegatSendOtpOptions): Promise; /** * Vendor extra: verify a code previously sent with {@link sendOtp} via * `verifyOTPCode.php`. Not part of {@link SmsTransport} — call on * {@link MsegatTransport} directly. Throws {@link MsegatError} when the code * is invalid, expired (`400`), or not found (`404`). */ verifyOtp(options: MsegatVerifyOtpOptions): Promise; /** * Credential check via `GET /gw/Credits.php` (no SMS sent). * Postman success body is a bare balance number (e.g. `"272.6"`). */ verify(): Promise; }