Derive the notation names from one table and refuse an smsIdFormat that is not the pair

This commit is contained in:
2026-08-30 22:45:02 +02:00
parent 8e5b9bb556
commit 696e018b77
12 changed files with 111 additions and 56 deletions
+5 -5
View File
@@ -1,7 +1,7 @@
import type { MessageState } from './defs/constants.ts';
import type { ParamValue } from './defs/types.ts';
import type { PduObject } from './pdu.ts';
import type { SmsIdFormat } from './sms-id.ts';
import type { SmsIdNotation } from './sms-id.ts';
import { consts, constsById, messageTypeOf } from './defs/constants.ts';
import { decodeMessage } from './message.ts';
import { normaliseSmsId } from './sms-id.ts';
@@ -164,11 +164,11 @@ function receiptBody(pduObj: PduObject): string {
function receiptId(
tlvId: ParamValue | undefined,
receipt: Receipt | undefined,
format: SmsIdFormat | undefined,
notation: SmsIdNotation | undefined,
): string | undefined {
const id = nonEmptyText(tlvId) ?? nonEmptyText(receipt?.id);
return id === undefined ? undefined : normaliseSmsId(id, format);
return id === undefined ? undefined : normaliseSmsId(id, notation);
}
function isMessageState(name: string | undefined): name is MessageState {
@@ -192,14 +192,14 @@ function receiptStatus(
}
/** The delivery report a deliver_sm carries, or nothing when it carries a message instead. */
export function dlrFromPdu(pduObj: PduObject, format?: SmsIdFormat): Dlr | undefined {
export function dlrFromPdu(pduObj: PduObject, notation?: SmsIdNotation): Dlr | undefined {
const type = messageType(pduObj);
if (type === 'other') return undefined;
const body = receiptBody(pduObj);
const receipt = body === '' ? undefined : parseReceipt(body);
const smsId = receiptId(pduObj.tlvs.receipted_message_id?.tagValue, receipt, format);
const smsId = receiptId(pduObj.tlvs.receipted_message_id?.tagValue, receipt, notation);
const { statusId, statusMsg } = receiptStatus(pduObj.tlvs.message_state?.tagValue, receipt);
if (type === 'unmarked' && (smsId === undefined || statusMsg === undefined)) return undefined;