fix(types): remove non-null assertions in remaining 12 files

Files fixed:
- messages-media.ts: stream/buffer guards, file path validation
- decode-wa-message.ts: message field guards, optional chaining
- version-cache.ts: narrowing after null checks
- jid-utils.ts: split result guards, user fallbacks
- communities.ts: attrs fallbacks with ?? operator
- sticker-pack.ts: response guards
- business.ts: attrs guards
- socket.ts: onClose guard, pairingCode guard, creds.me guard
- event-buffer.ts: null guards
- signal.ts: null guards
- encode.ts (WAM): id null check with continue
- upstream history.ts: conversations/pushnames null guards

All 26 files across the project are now corrected.
Total: ~248 non-null assertions replaced with proper null guards.

https://claude.ai/code/session_01E2cfX1N3sJgCJBTvzGazSG
This commit is contained in:
Claude
2026-02-09 00:32:04 +00:00
parent 7e88ddb858
commit 1c9fb86cc3
12 changed files with 215 additions and 104 deletions
+19 -13
View File
@@ -127,6 +127,10 @@ export function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: strin
const msgId = stanza.attrs.id
const from = stanza.attrs.from
if (!from) {
throw new Boom('Missing from attribute in message', { data: stanza })
}
const participant: string | undefined = stanza.attrs.participant
const recipient: string | undefined = stanza.attrs.recipient
@@ -137,21 +141,21 @@ export function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: strin
if (isPnUser(from) || isLidUser(from) || isHostedLidUser(from) || isHostedPnUser(from)) {
if (recipient && !isJidMetaAI(recipient)) {
if (!isMe(from!) && !isMeLid(from!)) {
if (!isMe(from) && !isMeLid(from)) {
throw new Boom('receipient present, but msg not from me', { data: stanza })
}
if (isMe(from!) || isMeLid(from!)) {
if (isMe(from) || isMeLid(from)) {
fromMe = true
}
chatId = recipient
} else {
chatId = from!
chatId = from
}
msgType = 'chat'
author = from!
author = from
} else if (isJidGroup(from)) {
if (!participant) {
throw new Boom('No participant in group message')
@@ -163,28 +167,28 @@ export function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: strin
msgType = 'group'
author = participant
chatId = from!
chatId = from
} else if (isJidBroadcast(from)) {
if (!participant) {
throw new Boom('No participant in group message')
}
const isParticipantMe = isMe(participant)
if (isJidStatusBroadcast(from!)) {
if (isJidStatusBroadcast(from)) {
msgType = isParticipantMe ? 'direct_peer_status' : 'other_status'
} else {
msgType = isParticipantMe ? 'peer_broadcast' : 'other_broadcast'
}
fromMe = isParticipantMe
chatId = from!
chatId = from
author = participant
} else if (isJidNewsletter(from)) {
msgType = 'newsletter'
chatId = from!
author = from!
chatId = from
author = from
if (isMe(from!) || isMeLid(from!)) {
if (isMe(from) || isMeLid(from)) {
fromMe = true
}
} else {
@@ -207,7 +211,7 @@ export function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: strin
const fullMessage: WAMessage = {
key,
category: stanza.attrs.category,
messageTimestamp: +stanza.attrs.t!,
messageTimestamp: +(stanza.attrs.t ?? 0),
pushName: pushname,
broadcast: isJidBroadcast(from)
}
@@ -241,8 +245,10 @@ export const decryptMessageNode = (
for (const { tag, attrs, content } of stanza.content) {
if (tag === 'verified_name' && content instanceof Uint8Array) {
const cert = proto.VerifiedNameCertificate.decode(content)
const details = proto.VerifiedNameCertificate.Details.decode(cert.details!)
fullMessage.verifiedBizName = details.verifiedName
if (cert.details) {
const details = proto.VerifiedNameCertificate.Details.decode(cert.details)
fullMessage.verifiedBizName = details.verifiedName
}
}
if (tag === 'unavailable' && attrs.type === 'view_once') {