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

219 lines (218 loc) 6.67 kB
import type { HttpClient } from "../client/HttpClient"; import type { Result } from "../types/Result"; import { MNotifyError } from "../errors/MNotifyError"; /** * Contact Group */ export interface Group { id: string; name: string; description?: string; contact_count: number; created_at: string; updated_at: string; } /** * Group creation input */ export interface CreateGroupInput { name: string; description?: string; } /** * Service for managing contact groups with mNotify API */ export declare class GroupService { private readonly client; constructor(client: HttpClient); private annotate; /** * Creates a new contact group (railway-oriented programming) * @param input - Group data * @returns Result containing created group or error * * @example * ```typescript * const result = await groupService.createGroupSafe({ * name: 'VIP Customers', * description: 'High-value customer segment' * }); * result.match({ * ok: (group) => console.log('Group created:', group), * err: (error) => console.error('Failed to create group:', error) * }); * ``` */ createGroupSafe(input: CreateGroupInput): Promise<Result<Group, MNotifyError>>; /** * Creates a new contact group (throws on error - legacy API) * @param input - Group data * @returns Created group * @throws {MNotifyError} On API failure * * @example * ```typescript * const group = await groupService.createGroup({ * name: 'VIP Customers', * description: 'High-value customer segment' * }); * ``` */ createGroup(input: CreateGroupInput): Promise<Group>; /** * Retrieves all groups (railway-oriented programming) * @returns Result containing array of groups or error * * @example * ```typescript * const result = await groupService.getGroupsSafe(); * if (result.isOk()) { * console.log('Groups:', result.value); * } * ``` */ getGroupsSafe(): Promise<Result<Group[], MNotifyError>>; /** * Retrieves all groups (throws on error - legacy API) * @returns Array of groups * @throws {MNotifyError} On API failure * * @example * ```typescript * const groups = await groupService.getGroups(); * console.log('Groups:', groups); * ``` */ getGroups(): Promise<Group[]>; /** * Retrieves a specific group by ID (railway-oriented programming) * @param id - Group ID * @returns Result containing group details or error * * @example * ```typescript * const result = await groupService.getGroupSafe('group_123'); * result.match({ * ok: (group) => console.log('Group:', group), * err: (error) => console.error('Failed to get group:', error) * }); * ``` */ getGroupSafe(id: string): Promise<Result<Group, MNotifyError>>; /** * Retrieves a specific group by ID (throws on error - legacy API) * @param id - Group ID * @returns Group details * @throws {MNotifyError} On API failure * * @example * ```typescript * const group = await groupService.getGroup('group_123'); * console.log('Group:', group); * ``` */ getGroup(id: string): Promise<Group>; /** * Adds a contact to a group (railway-oriented programming) * @param groupId - Group ID * @param contactId - Contact ID * @returns Result containing operation result or error * * @example * ```typescript * const result = await groupService.addContactToGroupSafe('group_123', 'contact_456'); * result.match({ * ok: (res) => console.log('Contact added:', res), * err: (error) => console.error('Failed to add contact:', error) * }); * ``` */ addContactToGroupSafe(groupId: string, contactId: string): Promise<Result<{ status: string; message: string; }, MNotifyError>>; /** * Adds a contact to a group (throws on error - legacy API) * @param groupId - Group ID * @param contactId - Contact ID * @returns Operation result * @throws {MNotifyError} On API failure * * @example * ```typescript * await groupService.addContactToGroup('group_123', 'contact_456'); * ``` */ addContactToGroup(groupId: string, contactId: string): Promise<{ status: string; message: string; }>; /** * Removes a contact from a group (railway-oriented programming) * @param groupId - Group ID * @param contactId - Contact ID * @returns Result containing operation result or error * * @example * ```typescript * const result = await groupService.removeContactFromGroupSafe('group_123', 'contact_456'); * result.match({ * ok: (res) => console.log('Contact removed:', res), * err: (error) => console.error('Failed to remove contact:', error) * }); * ``` */ removeContactFromGroupSafe(groupId: string, contactId: string): Promise<Result<{ status: string; message: string; }, MNotifyError>>; /** * Removes a contact from a group (throws on error - legacy API) * @param groupId - Group ID * @param contactId - Contact ID * @returns Operation result * @throws {MNotifyError} On API failure * * @example * ```typescript * await groupService.removeContactFromGroup('group_123', 'contact_456'); * ``` */ removeContactFromGroup(groupId: string, contactId: string): Promise<{ status: string; message: string; }>; /** * Deletes a group (railway-oriented programming) * @param id - Group ID * @returns Result containing deletion confirmation or error * * @example * ```typescript * const result = await groupService.deleteGroupSafe('group_123'); * result.match({ * ok: (res) => console.log('Group deleted:', res), * err: (error) => console.error('Failed to delete group:', error) * }); * ``` */ deleteGroupSafe(id: string): Promise<Result<{ status: string; message: string; }, MNotifyError>>; /** * Deletes a group (throws on error - legacy API) * @param id - Group ID * @returns Deletion confirmation * @throws {MNotifyError} On API failure * * @example * ```typescript * await groupService.deleteGroup('group_123'); * ``` */ deleteGroup(id: string): Promise<{ status: string; message: string; }>; }