Leave an unknown notation alone and read a receipt's TLV as the id the submit answered
This commit is contained in:
+6
-8
@@ -3,18 +3,17 @@ const notations = {
|
||||
hex: { digits: /^[0-9a-f]+$/i, prefix: '0x' },
|
||||
};
|
||||
|
||||
const places = ['receipt', 'submitResp'] as const;
|
||||
|
||||
/** The notation a peer writes message ids in. */
|
||||
export type SmsIdNotation = keyof typeof notations;
|
||||
|
||||
/** The notation per place the peer writes an id. An omitted place is left as it arrived. */
|
||||
export type SmsIdFormat = {
|
||||
receipt?: SmsIdNotation | undefined;
|
||||
submitResp?: SmsIdNotation | undefined;
|
||||
};
|
||||
export type SmsIdFormat = Partial<Record<typeof places[number], SmsIdNotation | undefined>>;
|
||||
|
||||
export const smsIdNotations: string[] = Object.keys(notations);
|
||||
|
||||
export const smsIdPlaces: (keyof SmsIdFormat)[] = ['receipt', 'submitResp'];
|
||||
export const smsIdPlaces: readonly string[] = places;
|
||||
|
||||
export function isSmsIdNotation(value: unknown): value is SmsIdNotation {
|
||||
return typeof value === 'string' && Object.hasOwn(notations, value);
|
||||
@@ -25,11 +24,10 @@ const maxIdLength = 64;
|
||||
|
||||
/**
|
||||
* The id as a plain decimal value, so an SMSC that answers a submit in one notation and writes the
|
||||
* receipt in another still correlates. An id the notation cannot read is left as it arrived, which
|
||||
* is what leaves a `<base>-<n>` id whole for DlrMerger.
|
||||
* receipt in another still correlates.
|
||||
*/
|
||||
export function normaliseSmsId(id: string, notation: SmsIdNotation | undefined): string {
|
||||
if (notation === undefined || id.length > maxIdLength) return id;
|
||||
if (!isSmsIdNotation(notation) || id.length > maxIdLength) return id;
|
||||
|
||||
const { digits, prefix } = notations[notation];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user