Let sendSms() name the esm_class messaging mode (#92)
* Regression tests for the messaging mode on sendSms() * Let sendSms() name the esm_class messaging mode * Document the messaging mode option and the decision behind it * Name the constants move for migrating consumers and share the refusal's value naming * Cover the messaging-mode refusals through submitSms() * Refuse transaction mode and a report under datagram mode on sendSms() * Narrow the mode checker and name the default mode once
This commit is contained in:
+26
-3
@@ -43,13 +43,10 @@ export const consts = {
|
||||
},
|
||||
ESM_CLASS: {
|
||||
CONVERSATION_ABORT: 0x18,
|
||||
DATAGRAM: 0x01,
|
||||
DELIVERY_ACKNOWLEDGEMENT: 0x08,
|
||||
FORWARD: 0x02,
|
||||
INTERMEDIATE_DELIVERY: 0x20,
|
||||
MC_DELIVERY_RECEIPT: 0x04,
|
||||
SET_REPLY_PATH: 0x80,
|
||||
STORE_FORWARD: 0x03,
|
||||
UDH_INDICATOR: 0x40,
|
||||
USER_ACKNOWLEDGEMENT: 0x10,
|
||||
},
|
||||
@@ -65,6 +62,13 @@ export const consts = {
|
||||
UNDELIVERABLE: 5,
|
||||
UNKNOWN: 7,
|
||||
},
|
||||
/** SMPP 3.4 5.2.12 bits 1-0 of esm_class, the field the rest of that octet is OR-ed into. */
|
||||
MESSAGING_MODE: {
|
||||
DATAGRAM: 0x01,
|
||||
FORWARD: 0x02,
|
||||
SMSC_DEFAULT: 0x00,
|
||||
STORE_FORWARD: 0x03,
|
||||
},
|
||||
NETWORK: {
|
||||
CDMA: 0x03,
|
||||
GENERIC: 0x00,
|
||||
@@ -114,6 +118,25 @@ export function messageTypeOf(esmClass: number): number {
|
||||
|
||||
export type ConstGroup = keyof typeof consts;
|
||||
export type MessageState = keyof typeof consts.MESSAGE_STATE;
|
||||
export type MessagingMode = keyof typeof consts.MESSAGING_MODE;
|
||||
|
||||
/** SMPP 3.4 2.10.3 carries transaction mode on `data_sm` alone, so a `submit_sm` never asks for it. */
|
||||
const transactionMode = 'FORWARD' satisfies MessagingMode;
|
||||
|
||||
export const defaultMessagingMode = 'SMSC_DEFAULT' satisfies MessagingMode;
|
||||
|
||||
export type SubmitMessagingMode = Exclude<MessagingMode, typeof transactionMode>;
|
||||
|
||||
export const submitMessagingModes: readonly string[] = Object.keys(consts.MESSAGING_MODE)
|
||||
.filter(mode => mode !== transactionMode);
|
||||
|
||||
export function isMessagingMode(value: unknown): value is MessagingMode {
|
||||
return typeof value === 'string' && Object.hasOwn(consts.MESSAGING_MODE, value);
|
||||
}
|
||||
|
||||
export function isSubmitMessagingMode(value: unknown): value is SubmitMessagingMode {
|
||||
return isMessagingMode(value) && value !== transactionMode;
|
||||
}
|
||||
|
||||
// Aliased values (NPI.IP === NPI.INTERNET === 0x0E) resolve to whichever name sorts last.
|
||||
export const constsById: Record<string, Record<number, string>> = {};
|
||||
|
||||
Reference in New Issue
Block a user