UNPKG

node-pdu

Version:

Creates and parses SMS PDU strings

1,298 lines (1,280 loc) 60.5 kB
/* * 📦 node-pdu * * 🏷️ Version: 2.1.1 * 📄 License: MIT * 🕒 Build: 2025-07-12T10:00:05.406Z * 🔗 Repository: git+https://github.com/JulianWowra/node-pdu.git * 👤 Author: jackkum <jackkum@bk.ru> * 👤 Maintainer: Julian Wowra <development@julianwowra.de> */ /** * Represents the Data Coding Scheme (DCS) of an SMS message. * * Defines how the message content is encoded, affecting character set selection and special message features. * It plays a key role in ensuring that the message content is correctly displayed on the receiving device. */ declare class DCS { static readonly CLASS_NONE = 0; static readonly CLASS_MOBILE_EQUIPMENT = 1; static readonly CLASS_SIM_SPECIFIC_MESSAGE = 2; static readonly CLASS_TERMINAL_EQUIPMENT = 3; static readonly INDICATION_TYPE_VOICEMAIL = 0; static readonly INDICATION_TYPE_FAX = 1; static readonly INDICATION_TYPE_EMAIL = 2; static readonly INDICATION_TYPE_OTHER = 3; static readonly ALPHABET_DEFAULT = 0; static readonly ALPHABET_8BIT = 1; static readonly ALPHABET_UCS2 = 2; static readonly ALPHABET_RESERVED = 3; private _encodeGroup; private _dataEncoding; private _compressedText; private _textAlphabet; private _useMessageClass; private _classMessage; private _discardMessage; private _storeMessage; private _storeMessageUCS2; private _dataCodingAndMessageClass; private _messageIndication; private _messageIndicationType; constructor(options?: DCSOptions); get encodeGroup(): number; get dataEncoding(): number; get compressedText(): boolean; get dataCodingAndMessageClass(): boolean; get discardMessage(): boolean; setDiscardMessage(): this; get storeMessage(): boolean; setStoreMessage(): this; get storeMessageUCS2(): boolean; setStoreMessageUCS2(): this; get messageIndication(): number; setMessageIndication(indication: number): this; get messageIndicationType(): number; setMessageIndicationType(type: number): this; get textTextCompressed(): boolean; setTextCompressed(compressed?: boolean): this; get textAlphabet(): number; setTextAlphabet(alphabet: number): this; get classMessage(): number; setClass(cls: number): this; get useMessageClass(): boolean; setUseMessageClass(use?: boolean): this; getValue(): number; toString(): string; } type DCSOptions = { encodeGroup?: number; dataEncoding?: number; compressedText?: boolean; textAlphabet?: number; useMessageClass?: boolean; classMessage?: number; discardMessage?: boolean; storeMessage?: boolean; storeMessageUCS2?: boolean; dataCodingAndMessageClass?: boolean; messageIndication?: number; messageIndicationType?: number; }; /** * Represents the Protocol Identifier (PID) of an SMS message. * * Specifies the type or nature of the message, allowing the system to handle it appropriately. It can * indicate special types of messages such as voicemail notifications or system messages, among others. */ declare class PID { static readonly PID_ASSIGNED = 0; static readonly PID_GSM_03_40 = 1; static readonly PID_RESERVED = 2; static readonly PID_SPECIFIC = 3; static readonly TYPE_IMPLICIT = 0; static readonly TYPE_TELEX = 1; static readonly TYPE_TELEFAX = 2; static readonly TYPE_VOICE = 4; static readonly TYPE_ERMES = 5; static readonly TYPE_NPS = 6; static readonly TYPE_X_400 = 17; static readonly TYPE_IEM = 18; private _pid; private _indicates; private _type; /** * Constructs a Protocol Identifier (PID) instance. * @param options An object containing optional parameters for the PID instance */ constructor(options?: PIDOptions); /** * Retrieves the Protocol Identifier (PID) value. * * The PID value is crucial for identifying the nature and handling of the SMS message within * the network. It determines if the message is of a specific type, such as voicemail * notifications or system messages. * * @returns The current PID value */ get pid(): number; /** * Sets the Protocol Identifier (PID) value. * * Allows specifying the nature of the SMS message by setting an appropriate PID value. The * value is masked to ensure it fits the allowed range defined by the protocol. * * @param pid The new PID value, which is masked to fit into the allowed range * @returns The instance of this PID, allowing for method chaining */ setPid(pid: number): this; /** * Retrieves the indicates value. * * This value is part of determining how the message should be handled or processed by the * receiving entity, contributing to the overall interpretation of the PID. * * @returns The current indicates value */ get indicates(): number; /** * Sets the indicates value. * * Modifies part of the PID to influence how the SMS message is processed by the network or * receiving device. The value is masked to ensure it adheres to the expected range. * * @param indicates The new indicates value, which is masked to the allowed range * @returns The instance of this PID, allowing for method chaining */ setIndicates(indicates: number): this; /** * Retrieves the type of the SMS message. * * The type provides further specification within the PID, defining the exact nature or * handling instructions for the message, such as whether it's a voice message or an email. * * @returns The current type value */ get type(): number; /** * Sets the type of the SMS message. * * This method allows for detailed specification of the message's nature, affecting how it is * processed. The type is masked to ensure it complies with the defined protocol specifications. * * @param type The new type value, masked to fit the allowed protocol range * @returns The instance of this PID, allowing for method chaining */ setType(type: number): this; /** * Computes and returns the combined value of the PID, including its indicates and type parts. * * This value is used for encoding the PID field in the SMS message, combining the general PID * with specific flags for message handling. * * @returns The combined PID value as a number */ getValue(): number; /** * Provides a string representation of the PID's combined value. * * Useful for logging or debugging, this method returns a string that represents the encoded * value of the PID, including its general identifier, indicates, and type components. * * @returns The PID's combined value as a string */ toString(): string; } type PIDOptions = { pid?: number; indicates?: number; type?: number; }; /** * Defines the Service Centre Address (SCA) format in SMS messages. * * Specifies the SCA format, crucial for SMS routing and delivery. Types may include international, * national, and others, ensuring compatibility across networks. */ declare class SCAType { static readonly TYPE_UNKNOWN = 0; static readonly TYPE_INTERNATIONAL = 1; static readonly TYPE_NATIONAL = 2; static readonly TYPE_ACCEPTER_INTO_NET = 3; static readonly TYPE_SUBSCRIBER_NET = 4; static readonly TYPE_ALPHANUMERICAL = 5; static readonly TYPE_TRIMMED = 6; static readonly TYPE_RESERVED = 7; static readonly PLAN_UNKNOWN = 0; static readonly PLAN_ISDN = 1; static readonly PLAN_X_121 = 2; static readonly PLAN_TELEX = 3; static readonly PLAN_NATIONAL = 8; static readonly PLAN_INDIVIDUAL = 9; static readonly PLAN_ERMES = 10; static readonly PLAN_RESERVED = 15; private _type; private _plan; constructor(value?: number); /** * Retrieves the type of the Service Centre Address (SCA). * The type indicates the format or category of the SCA, such as international, national, or alphanumeric. * * @returns The type of the SCA */ get type(): number; /** * Sets the type of the Service Centre Address (SCA). * This method allows updating the type of the SCA, ensuring compatibility and proper routing. * * @param type The new type of the SCA * @returns The instance of this SCAType, allowing for method chaining */ setType(type: number): this; /** * Retrieves the numbering plan identification of the Service Centre Address (SCA). * The plan indicates the numbering plan used for the SCA, such as ISDN, national, or individual. * * @returns The numbering plan identification of the SCA */ get plan(): number; /** * Sets the numbering plan identification of the Service Centre Address (SCA). * This method allows updating the numbering plan used for the SCA, ensuring compatibility and proper routing. * * @param plan The new numbering plan identification for the SCA * @returns The instance of this SCAType, allowing for method chaining */ setPlan(plan: number): this; /** * Retrieves the numerical value representing the SCAType. * This value is used internally and for PDU encoding. * * @returns The numerical value representing the SCAType */ getValue(): number; /** * Converts the SCAType instance to its hexadecimal string representation. * * This method converts the SCAType instance to its hexadecimal string representation suitable for * inclusion in PDUs. * * @returns The hexadecimal string representation of the SCAType */ toString(): string; } /** * Represents the Service Centre Address (SCA) of an SMS message. * * The address of the SMSC responsible for the delivery of the message. It is crucial for routing the SMS * through the correct service center to reach the intended recipient. */ declare class SCA { type: SCAType; private _isAddress; private _size; private _encoded; private _phone; constructor(isAddress?: boolean, options?: SCAOptions); /** * Indicates whether the current instance represents an address. * @returns True if the instance represents an address; otherwise, false */ get isAddress(): boolean; /** * Retrieves the size of the encoded address. * The size is calculated based on the encoding scheme used. * * @returns The size of the encoded address */ get size(): number; /** * Retrieves the encoded representation of the address. * The encoding scheme depends on the type of address. * * @returns The encoded address as a hexadecimal string */ get encoded(): string; /** * Retrieves the phone number associated with the address. * @returns The phone number associated with the address */ get phone(): string | null; /** * Sets the phone number associated with the address. * * This method allows setting the phone number for the address. It also performs * encoding based on the address type and detects the type of address if requested. * * @param phone The phone number to set * @param detectType Flag indicating whether to detect the address type * @param SC Flag indicating whether the address is a service center address * * @returns The instance of this SCA, allowing for method chaining */ setPhone(phone: string, detectType?: boolean, SC?: boolean): this; private detectScaType; /** * Retrieves the offset for the SCA in the PDU. * The offset indicates the position of the SCA within the PDU. * * @returns The offset for the SCA in the PDU */ getOffset(): number; /** * Converts the SCA instance to a string representation. * * This method converts the SCA instance to its string representation suitable for * inclusion in the PDU. * * @returns The string representation of the SCA */ toString(): string; /** * Maps and decodes a hexadecimal letter to its corresponding character. * This method decodes a hexadecimal letter back to its original character value. * * @param letter The hexadecimal letter to decode * @returns The decoded character */ static mapFilterDecode(letter: string): string; /** * Maps and encodes a character to its corresponding hexadecimal representation. * This method encodes a character to its hexadecimal representation. * * @param letter The character to encode * @returns The encoded hexadecimal representation */ static mapFilterEncode(letter: string): string; } type SCAOptions = { type?: SCAType; }; /** * Represents the abstract base for different types of Protocol Data Units (PDU) in SMS messaging. * * This abstract class defines the core structure for various SMS PDU types and * ensuring standardized handling and processing across different messaging operations. */ declare abstract class PDUType { abstract messageTypeIndicator: number; static readonly SMS_SUBMIT = 1; static readonly SMS_DELIVER = 0; static readonly SMS_REPORT = 2; static readonly VPF_NONE = 0; static readonly VPF_SIEMENS = 1; static readonly VPF_RELATIVE = 2; static readonly VPF_ABSOLUTE = 3; private readonly replyPath; private readonly rejectDuplicates; private _userDataHeader; private _statusReportRequest; private _validityPeriodFormat; /** * Constructs a PDUType instance. * @param params Parameters for configuring the PDUType instance */ constructor(params: TypeParams); /** * Retrieves the User Data Header (UDH) indicator status. * * The User Data Header is part of the SMS payload and can contain various control * information such as concatenated message reference numbers, port numbers for WAP * Push, and other service indications. This indicator specifies whether UDH is present. * * @returns The current status of the User Data Header indicator */ get userDataHeader(): number; /** * Sets the User Data Header (UDH) indicator. * * This method configures the presence of a User Data Header in the SMS message. It is * primarily used for advanced messaging features such as concatenated SMS or application * port addressing. The value is masked to ensure it is within valid range. * * @param userDataHeader The desired status for the UDH indicator (0 or 1) * @returns The instance of this PDUType, allowing for method chaining */ setUserDataHeader(userDataHeader: number): this; /** * Retrieves the Status Report Request (SRR) status. * * The SRR is a feature in SMS that requests the network to send a delivery report * for the sent message. This indicator specifies whether such a report is requested. * * @returns The current status of the Status Report Request indicator */ get statusReportRequest(): number; /** * Sets the Status Report Request (SRR) indicator. * * This method enables or disables the request for a delivery report for the SMS message. * It ensures the delivery status can be tracked. The value is masked to ensure it is * within valid range. * * @param srr The desired status for the SRR indicator (0 or 1) * @returns The instance of this PDUType, allowing for method chaining */ setStatusReportRequest(srr: number): this; /** * Retrieves the Validity Period Format (VPF). * * The VPF specifies the format of the validity period of the SMS message, dictating how * long the message should be stored in the network before delivery is attempted. It supports * several formats including none, relative, and absolute. * * @returns The current format of the validity period */ get validityPeriodFormat(): number; /** * Sets the Validity Period Format (VPF) for the SMS message. * * This method configures the time frame in which the SMS should be delivered. It is crucial * for time-sensitive messages. The value is masked and validated to ensure it corresponds to * one of the predefined formats. An error is thrown for invalid formats. * * @param validityPeriodFormat The desired format for the message validity period * @returns The instance of this PDUType, allowing for method chaining */ setValidityPeriodFormat(validityPeriodFormat: number): this; /** * Calculates and returns the overall value of the PDU type based on its components. * * This method aggregates the various indicators and settings into a single value, which * represents the configuration of the PDU type. It is used for generating the final PDU * string representation. * * @returns The aggregated value of the PDU type settings */ getValue(): number; /** * Generates a string representation of the PDU type value. * * This method utilizes a helper function to convert the aggregated PDU type value into * a hexadecimal string. It is useful for logging and debugging purposes to see the * encoded PDU type. * * @returns A hexadecimal string representation of the PDU type value */ toString(): string; } type TypeParams = { replyPath: number; userDataHeader: number; statusReportRequest: number; validityPeriodFormat: number; rejectDuplicates: number; }; /** * Represents the PDU type for an SMS-DELIVER message in GSM SMS messaging. */ declare class DeliverType extends PDUType { readonly messageTypeIndicator = 0; /** * Constructs a DeliverType instance. * @param params Parameters for configuring the DeliverType instance */ constructor(params?: DeliverParams); } type DeliverParams = { replyPath?: number; userDataHeader?: number; statusReportRequest?: number; mms?: number; }; /** * Represents the PDU type for an SMS-REPORT message in GSM SMS messaging. */ declare class ReportType extends PDUType { readonly messageTypeIndicator = 2; /** * Constructs a ReportType instance. * @param params Parameters for configuring the ReportType instance */ constructor(params?: ReportParams); } type ReportParams = { replyPath?: number; userDataHeader?: number; statusReportRequest?: number; mms?: number; }; /** * Represents the PDU type for an SMS-SUBMIT message in GSM SMS messaging. */ declare class SubmitType extends PDUType { readonly messageTypeIndicator = 1; /** * Constructs a SubmitType instance. * @param params Parameters for configuring the SubmitType instance */ constructor(params?: SubmitParams); } type SubmitParams = { replyPath?: number; userDataHeader?: number; statusReportRequest?: number; validityPeriodFormat?: number; rejectDuplicates?: number; }; /** * An abstract base class for Protocol Data Units (PDU) in SMS messaging. * * Defines the basic structure and functionalities common to all types of PDUs used in the GSM SMS system. * This class serves as a foundation for more specific PDU classes like Submit, Deliver, and Report. */ declare abstract class PDU { abstract type: DeliverType | ReportType | SubmitType; private _address; private _serviceCenterAddress; private _protocolIdentifier; private _dataCodingScheme; /** * Constructs a Protocol Description Unit (PDU) instance. * * @param address The address as a string or SCA instance * @param options An object containing optional parameters for the PDU instance */ constructor(address: string | SCA, options?: PDUOptions); /** * Represents the address of the recipient. * @returns The current address as an SCA instance */ get address(): SCA; /** * Sets the address of the recipient. * * This method updates the address for the PDU. It accepts either a string or an SCA instance. * If a string is provided, it converts it to an SCA instance. * * @param address The new address, either as a string or an SCA instance * @returns The instance of this PDU, allowing for method chaining */ setAddress(address: string | SCA): this; /** * Returns the Service Center Address (SCA) of the SMS message. * * The Service Center Address is used by the GSM network to know where to send the SMS. * * @returns The current service center address as an SCA instance */ get serviceCenterAddress(): SCA; /** * Sets the Service Center Address (SCA) for the SMS message. * * This address is crucial for routing the message through the GSM network. The method accepts * either an SCA instance directly or a string that will be converted into an SCA. * * @param address The new service center address, either as a string or an SCA instance * @returns The instance of this PDU, allowing for method chaining */ setServiceCenterAddress(address: SCA | string): this; /** * Retrieves the Protocol Identifier (PID) of the SMS message. * * The PID is used to indicate interworking and teleservices. It determines how the message * should be processed by the receiving entity. * * @returns The current protocol identifier as a PID instance */ get protocolIdentifier(): PID; /** * Sets the Protocol Identifier (PID) for the SMS message. * * This method allows customization of the message's PID, which can affect delivery and processing. * Only PID instances are accepted to ensure correct format and compatibility. * * @param pid The new protocol identifier as a PID instance * @returns The instance of this PDU, allowing for method chaining */ setProtocolIdentifier(pid: PID): this; /** * Retrieves the Data Coding Scheme (DCS) of the SMS message. * * The DCS indicates the data type of the message content (e.g., text, UCS2, etc.) and may * influence how the message is displayed on the recipient's device. * * @returns The current data coding scheme as a DCS instance */ get dataCodingScheme(): DCS; /** * Sets the Data Coding Scheme (DCS) for the SMS message. * * Adjusting the DCS can change how the message content is interpreted and displayed by the * recipient's device. This method accepts only DCS instances to ensure proper format. * * @param dcs The new data coding scheme as a DCS instance * @returns The instance of this PDU, allowing for method chaining */ setDataCodingScheme(dcs: DCS): this; private findAddress; } type PDUOptions = { serviceCenterAddress?: SCA; protocolIdentifier?: PID; dataCodingScheme?: DCS; }; /** * Represents the Validity Period (VP) of an SMS message. * * Defines how long an SMS is stored at the SMSC before delivery attempts cease. This duration * ensures messages remain relevant and can vary from minutes to days based on the sender's preference. */ declare class VP { static readonly PID_ASSIGNED = 0; private _datetime; private _interval; /** * Constructs a Validity Period (VP) instance. * @param options An object containing optional parameters for the VP instance */ constructor(options?: VPOptions); /** * Retrieves the datetime set for the Validity Period. * * This property represents the exact date and time the SMS should be considered valid. * If null, it implies that a specific datetime has not been set for this validity period. * * @returns The datetime as a Date object or null if not set */ get dateTime(): Date | null; /** * Sets the datetime for the SMS Validity Period. * * This method allows setting a specific date and time until which the SMS is considered valid. * Can be set using a Date object or a string that can be parsed into a Date. * * @param datetime The datetime to set as a Date object or a string representation * @returns The instance of this VP, allowing for method chaining */ setDateTime(datetime: string | Date): this; /** * Retrieves the interval set for the Validity Period. * * This property represents the duration in seconds for which the SMS should be considered valid. * If null, it implies that a specific interval has not been set for this validity period. * * @returns The interval in seconds or null if not set */ get interval(): number | null; /** * Sets the interval for the SMS Validity Period. * * This method allows setting a specific duration in seconds until which the SMS is considered valid. * It's an alternative to setting a specific datetime. * * @param interval The interval in seconds to set for the validity period * @returns The instance of this VP, allowing for method chaining */ setInterval(interval: number): this; /** * Converts the Validity Period to a PDU string representation. * * This method generates a string suitable for inclusion in a PDU, based on the validity period's format. * It can handle both absolute and relative formats and adjusts the PDU's validity period format accordingly. * This is critical for ensuring that the SMS's validity period is correctly interpreted by the SMSC. * * @param pdu The PDU instance to which this validity period belongs * @returns A string representation of the validity period for inclusion in the PDU */ toString(pdu: PDU): string; } type VPOptions = { datetime?: Date; interval?: number; }; /** * Represents a GSM SMS Submit PDU. * * Facilitates sending SMS messages from devices to the SMSC. It's critical for any application or service * that needs to initiate outbound text messages. */ declare class Submit extends PDU { private _type; private _data; private _messageReference; private _validityPeriod; /** * Constructs a SMS Submit PDU instance. * * @param address The recipents address as a string or an instance of SCA * @param data The message content as a string or an instance of Data * @param options An object containing optional parameters for the Submit instance */ constructor(address: string | SCA, data: string | Data, options?: SubmitOptions); /** * Retrieves the message type for this Submit PDU. * * This property represents the specific characteristics and parameters related to the submission of the SMS message, * such as whether it's a standard message, a status report request, etc. * * @returns The current SubmitType instance, defining the message type */ get type(): SubmitType; /** * Sets the message type for this Submit PDU. * * Allows for specifying the type of SMS submit message, adjusting its parameters like whether it requests * a status report, among other options. * * @param type The new SubmitType instance to set as the message type * @returns The instance of this Submit, allowing for method chaining */ setType(type: SubmitType): this; /** * Retrieves the data/content of the SMS message. * * This property holds the actual message content that will be sent, which can be in various formats * (e.g., plain text, binary data) depending on the data coding scheme. * * @returns The current Data instance containing the message content */ get data(): Data; /** * Sets the data/content of the SMS message. * * This method allows the message content to be updated, accepting either a string (which will be * converted to a Data instance internally) or a Data instance directly. * * @param data The new message content, either as a string or a Data instance * @returns The instance of this Submit, allowing for method chaining */ setData(data: string | Data): this; /** * Retrieves the message reference number for this Submit PDU. * * The message reference is a unique identifier for the message, used for tracking purposes and * to correlate delivery reports with the original messages. * * @returns The current message reference number */ get messageReference(): number; /** * Sets the message reference number for this Submit PDU. * * This method allows setting a custom message reference number for tracking and correlation purposes. * * @param messageReference The new message reference number * @returns The instance of this Submit, allowing for method chaining */ setMessageReference(messageReference: number): this; /** * Retrieves the Validity Period (VP) for the SMS message. * * The validity period indicates how long the message is valid for delivery before it expires. * This can be specified as an absolute date/time or as a time interval from the submission. * * @returns The current validity period as a VP instance */ get validityPeriod(): VP; /** * Sets the Validity Period (VP) for the SMS message. * * This method allows specifying how long the message is valid for delivery before it expires. * The validity period can be set as an absolute date/time or as a time interval from the submission. * * @param value The new validity period, either as a VP instance, a string (for absolute date/time), or a number (for time interval) * @returns The instance of this Submit, allowing for method chaining */ setValidityPeriod(value: VP | string | number): this; private findData; /** * Retrieves all parts of the message data. * * For messages that are split into multiple parts (e.g., concatenated SMS), this method returns * all parts as an array. * * @returns An array of Data parts representing the message content */ getParts(): Part[]; /** * Retrieves all parts of the message as strings. * * This method is useful for concatenated messages, converting each part of the message data * into a string format based on the current data coding scheme. * * @returns An array of strings, each representing a part of the message content */ getPartStrings(): string[]; /** * Generates a string representation of the start of the PDU. * * This method constructs the initial part of the PDU string, including information like the * service center address, message type, message reference number, sender's address, protocol identifier, * data coding scheme, and validity period. * * @returns A string representing the start of the PDU */ getStart(): string; /** * Converts the entire Submit PDU into a string representation. * * This method is intended to provide a complete textual representation of the Submit PDU, * including all headers and the message content, formatted according to the PDU protocol. * * @returns A string representation of the Submit PDU */ toString(): string; } type SubmitOptions = PDUOptions & { type?: SubmitType; messageReference?: number; validityPeriod?: VP; }; /** * Represents the header information in a segmented SMS message part. * * Contains metadata essential for the reassembly of segmented SMS messages, such as part numbering and * reference identifiers. It ensures that multipart messages are correctly reconstructed upon receipt. */ declare class Header { static readonly IE_CONCAT_8BIT_REF = 0; static readonly IE_CONCAT_16BIT_REF = 8; private ies; private concatIeIdx?; /** * Constructs a Header instance. * @param params The parameters for constructing the Header instance */ constructor(params: HeaderParams); /** * Converts the header information to an object. * * This function is useful for serializing the header information, including the message reference number, * total number of segments, and current segment number. It's particularly useful for diagnostics or * interfacing with systems that require these details in a structured format. * * @returns An object containing the pointer */ toJSON(): { POINTER: number | undefined; SEGMENTS: number | undefined; CURRENT: number | undefined; }; /** * Calculates the total size of the User Data Header Length (UDHL). * * The size is calculated based on the length of all Information Elements (IEs) included in the header. * This is crucial for correctly encoding and decoding segmented SMS messages. * * @returns The total size of the UDHL */ getSize(): number; /** * Retrieves the type of the concatenation Information Element (IE). * * This method checks if there's a known concatenation IE present and returns its type. * It distinguishes between 8-bit and 16-bit reference numbers for concatenated messages. * * @returns The type of the concatenation IE, or undefined if not present */ getType(): number | undefined; /** * Gets the size of the pointer (message reference number) in bytes. * * The size is determined based on the type of concatenation IE present, reflecting the * length of the message reference number field. * * @returns The size of the pointer in bytes, or 0 if no concatenation IE is present */ getPointerSize(): number; /** * Retrieves the message reference number for the segmented SMS message. * * This number is used to correlate all segments of a multi-part SMS message, ensuring * they can be correctly reassembled upon receipt. * * @returns The message reference number, or 0 if no concatenation IE is present */ getPointer(): number | undefined; /** * Gets the total number of segments in the segmented SMS message. * * This information is critical for understanding how many parts the message has been * divided into, enabling correct reassembly. * * @returns The total number of segments, or 1 if no concatenation IE is present */ getSegments(): number | undefined; /** * Retrieves the current segment number of this part of the segmented SMS message. * * This number indicates the order of the current segment in the sequence of the total * message parts, aiding in proper reconstruction. * * @returns The current segment number, or 1 if no concatenation IE is present */ getCurrent(): number | undefined; /** * Generates a string representation of the User Data Header (UDH). * * This method constructs the UDH string by concatenating the encoded lengths and data of all * Information Elements (IEs), prefixed with the overall UDH length. It's essential for * encoding the header part of segmented SMS messages. * * @returns A string representing the encoded User Data Header */ toString(): string; } type HeaderParams = { POINTER: number; SEGMENTS: number; CURRENT: number; } | { type: number; dataHex: string; }[]; type IES = { type: number; dataHex: string; data?: { msgRef: number; maxMsgNum: number; msgSeqNo: number; }; }; /** * Represents a part of a segmented SMS message. * * Used for messages that exceed the size limit for a single SMS and must be split. Each part contains * a segment of the full message, facilitating the reassembly of the complete message by the recipient. */ declare class Part { readonly data: string; readonly size: number; readonly text: string; readonly header: Header | null; /** * Constructs a new Part instance for a segmented SMS message. * * @param data The raw data of this message part * @param size The size of this part, including headers and content * @param text The decoded text content of this part * @param header An optional header for concatenated message support */ constructor(data: string, size: number, text: string, header?: Header); private getPduString; private getPartSize; /** * Generates a string representation of this SMS part, suitable for transmission. * * This method constructs the PDU string for this part by concatenating the PDU start, * the size of the part, any headers, and the data content. * * @param pdu The PDU (either Deliver or Submit) that this part belongs to. * @returns A string representing the PDU for this part of the message. */ toString(pdu: Deliver | Submit): string; } /** * Represents the data content of an SMS message. * * Holds the actual message content, whether text or binary data. It is central to the purpose of SMS, * conveying the intended information from sender to recipient. */ declare class Data { static readonly HEADER_SIZE = 7; private _data; private _size; private _parts; private _isUnicode; /** * Constructs a Data instance. * @param options An object containing optional parameters for the Data instance */ constructor(options?: DataOptions); /** * Gets the raw data of the SMS message. * * This property holds the actual content of the message, which could be text or binary data, * depending on how the message was encoded. * * @returns The raw data as a string */ get data(): string; /** * Retrieves the size of the message data. * * The size is determined based on the encoding and content of the message. It reflects the * number of characters or bytes. * * @returns The size of the data */ get size(): number; /** * Provides access to the individual parts of the message. * * For longer messages that are split into multiple parts (segments), this getter allows access * to each part. Each part contains a portion of the message data along with metadata. * * @returns An array of Part instances, each representing a segment of the message */ get parts(): Part[]; /** * Indicates whether the message data is encoded using Unicode. * * This property is true if the message content includes characters that require Unicode encoding * (e.g., non-Latin characters). Otherwise, it's false. * * @returns A boolean indicating if the message data is Unicode. */ get isUnicode(): boolean; /** * Sets the data for the SMS message. * * This method encodes the provided data string according to the specified PDU type (Deliver or Submit) * and updates the message parts accordingly. It handles encoding, part splitting, and header preparation. * * @param data The new message data as a string * @param pdu The PDU instance (Deliver or Submit) associated with this data * @returns The instance of this Data, allowing for method chaining */ setData(data: string, pdu: Deliver | Submit): this; private checkData; private prepareParts; private partExists; private sortParts; private splitMessage; /** * Retrieves the textual content of the SMS message. * * This method decodes the raw data into a readable text format, considering the encoding scheme * (e.g., GSM 7-bit, UCS-2) used for the message. * * @returns The decoded text of the message */ getText(): string; /** * Appends the parts from another PDU to this data instance. * * This method is used to combine the parts of another message (Deliver or Submit) into this one, * effectively concatenating the messages. It ensures parts are added only once and sorts them. * * @param pdu The PDU instance (Deliver or Submit) whose parts are to be appended */ append(pdu: Deliver | Submit): void; } type DataOptions = { data?: string; size?: number; parts?: Part[]; isUnicode?: boolean; }; /** * A utility class providing static methods for encoding and decoding SMS messages. * * This class contains methods for converting text into various encoding formats used in SMS, * such as GSM 7-bit, 8-bit, and UCS-2 (16-bit). It also includes utility methods * for handling characters and converting values to hexadecimal strings. */ declare class Helper { static readonly ALPHABET_7BIT = "@\u00A3$\u00A5\u00E8\u00E9\u00F9\u00EC\u00F2\u00C7\n\u00D8\u00F8\r\u00C5\u00E5\u0394_\u03A6\u0393\u039B\u03A9\u03A0\u03A8\u03A3\u0398\u039E\u001B\u00C6\u00E6\u00DF\u00C9 !\"#\u00A4%&'()*+,-./0123456789:;<=>?\u00A1ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00C4\u00D6\u00D1\u00DC`\u00BFabcdefghijklmnopqrstuvwxyz\u00E4\u00F6\u00F1\u00FC\u00E0"; static readonly EXTENDED_TABLE = "````````````````````^```````````````````{}`````\\````````````[~]`|````````````````````````````````````\u20AC``````````````````````````"; static readonly limitNormal = 140; static readonly limitCompress = 160; static readonly limitUnicode = 70; private static readonly TEXT_ENCODER; private static readonly TEXT_DECODER; /** * Converts a hex string to a Uint8Array. * * @param hex The hex string to convert * @returns A Uint8Array representing the hex string */ static hexToUint8Array(hex: string): Uint8Array; /** * Converts an ASCII string to a Uint8Array. * * @param ascii The ASCII string to convert * @returns A Uint8Array representing the ASCII string */ static asciiToUint8Array(ascii: string): Uint8Array; /** * Converts the first two characters of a hexadecimal string to a number. * * @param hexStr The hexadecimal string to convert * @returns The number represented by the first two characters of the hexadecimal string */ static getByteFromHex(hexStr: string): number; /** * Capitalizes the first character of the input string. * * @param str The string to capitalize * @returns The input string with its first character capitalized */ static ucfirst(str: string): string; /** * Returns the Unicode code point of the first character of the input string. * * @param char A single character string * @returns The Unicode code point of the character */ static order(char: string): number; /** * Returns the character represented by the specified Unicode code point. * * @param order The Unicode code point * @returns A string containing the character represented by the code point */ static char(order: number): string; /** * Decodes a 16-bit encoded string into a human-readable text. * * @param text The 16-bit encoded hexadecimal string * @returns The decoded text */ static decode16Bit(text: string): string; /** * Decodes an 8-bit encoded string into a human-readable text. * * @param text The 8-bit encoded hexadecimal string * @returns The decoded text */ static decode8Bit(text: string): string; /** * Decodes a 7-bit encoded string into a human-readable text. * * @param text The 7-bit encoded hexadecimal string * @param inLen The length of the input data in septets * @param alignBits The number of bits for alignment * * @returns The decoded text */ static decode7Bit(text: string, inLen?: number, alignBits?: number): string; /** * Encodes a text string into 8-bit hexadecimal PDU format. * * @param text The text to encode * @returns An object containing the length of the encoded text and the result as a hexadecimal string */ static encode8Bit(text: string): { length: number; result: string; }; /** * Encodes a text string into 7-bit hexadecimal PDU format. * * @param text The text to encode * @param alignBits The number of bits for alignment, if needed * * @returns An object containing the length of the encoded text in septets and the result as a hexadecimal string */ static encode7Bit(text: string, alignBits?: number): { length: number; result: string; }; /** * Encodes a text string into 16-bit hexadecimal PDU format. * * @param text The text to encode * @returns An object containing the length of the encoded text in septets and the result as a hexadecimal string */ static encode16Bit(text: string): { length: number; result: string; }; /** * Converts a number to a hexadecimal string with optional zero padding. * * @param number The number to convert * @param fill The minimum length of the resulting string, padded with zeros if necessary * @returns The number as a hexadecimal string */ static toStringHex(number: number, fill?: number): string; } /** * Represents the Service Centre Time Stamp (SCTS) of an SMS message. * * Marks the time and date the SMSC received the message, used in delivery reports and incoming * messages for timing analysis and record-keeping, providing a temporal reference for the message's handling. */ declare class SCTS { readonly time: number; readonly tzOff: number; /** * Constructs a Service Centre Time Stamp (SCTS) instance. * * @param date The date object representing the time and date the message was received * @param tzOff The time zone offset in minutes, defaults to the local time zone offset if not provided */ constructor(date: Date, tzOff?: number); private getDateTime; private getDateWithOffset; /** * Converts the SCTS to an ISO 8601 string format with a custom time zone offset. * * This method formats the date and time into an easily readable ISO 8601 format, * adjusting for the stored time zone offset to reflect the local time at the service centre. * * @returns The SCTS as an ISO 8601 formatted string with a custom time zone offset. */ getIsoString(): string; /** * Converts the SCTS to a string representation based on the SMS PDU specifications. * * This method formats the service centre time stamp into a semi-octet representation suitable * for inclusion in a PDU message, converting the date and time components and including the * time zone in a standardized format. * * @returns The SCTS as a string formatted according to the SMS PDU specifications */ toString(): string; } type index_DCS = DCS; declare const index_DCS: typeof DCS; type index_DCSOptions = DCSOptions; type index_Data = Data; declare const index_Data: typeof Data; type index_DataOptions = DataOptions; type index_DeliverParams = DeliverParams; type index_DeliverType = DeliverType; declare const index_DeliverType: typeof DeliverType; type index_Header = Header; declare const index_Header: typeof Header; type index_HeaderParams = HeaderParams; type index_Helper = Helper; declare const index_Helper: typeof Helper; type index_IES = IES; type index_PDU = PDU; declare const index_PDU: typeof PDU; type index_PDUOptions = PDUOptions; type index_PDUType = PDUType; declare const index_PDUType: typeof PDUType; type index_PID = PID; declare const index_PID: typeof PID; type index_PIDOptions = PIDOptions; type index_Part = Part; declare const index_Part: typeof Part; type index_ReportParams = ReportParams; type index_ReportType = ReportType; declare const index_ReportType: typeof ReportType; type index_SCA = SCA; declare const index_SCA: typeof SCA; type index_SCAOptions = SCAOptions; type index_SCAType = SCAType; declare const index_SCAType: typeof SCAType; type index_SCTS = SCTS; declare const index_SCTS: typeof SCTS; type index_SubmitParams = SubmitParams; type index_SubmitType = SubmitType; declare const index_SubmitType: typeof SubmitType; type index_TypeParams = TypeParams; type index_VP = VP; declare const index_VP: typeof VP; type index_VPOptions = VPOptions; declare namespace index { export { index_DCS as DCS, type index_DCSOptions as DCSOptions, index_Data as Data, type index_DataOptions as DataOptions, type index_DeliverParams as DeliverParams, index_DeliverType as DeliverType, index_Header as Header, type index_HeaderParams as HeaderParams, index_Helper as Helper, type index_IES as IES, index_PDU as PDU, type index_PDUOptions as PDUOptions, index_PDUType as PDUType, index_PID as PID, type index_PIDOptions as PIDOptions, index_Part as Part, type index_ReportParams as ReportParams, index_ReportType as ReportType, index_SCA as SCA, type index_SCAOptions as SCAOptions, index_SCAType as SCAType, index_SCTS as SCTS, type index_SubmitParams as SubmitParams, index_SubmitType as SubmitType, type index_TypeParams as TypeParams, index_VP as VP, type index_VPOptions as VPOptions }; } /** * Represents a GSM SMS Deliver PDU. * * Used for receiving SMS messages. It includes information like the sender's address and the message content, * essential for any application or service that needs to process or display incoming text messages to users. */ declare class Deliver extends PDU { private _type; private _data; private _serviceCenterTimeStamp; /** * Constructs a SMS Deliver PDU instance. * * @param address The sender's address as a string or an instance of SCA * @param data The message content as a string or an