project: Move to ESM Modules

This commit is contained in:
Rajeh Taher
2025-07-17 13:54:17 +03:00
parent 19124426b2
commit 787aed88b8
69 changed files with 5143 additions and 4757 deletions
+14 -14
View File
@@ -1,9 +1,9 @@
import { Boom } from '@hapi/boom'
import { proto } from '../../WAProto'
import { SignalRepository, WAMessage, WAMessageKey } from '../Types'
import type { SignalRepository, WAMessage, WAMessageKey } from '../Types'
import {
areJidsSameUser,
BinaryNode,
type BinaryNode,
isJidBroadcast,
isJidGroup,
isJidMetaIa,
@@ -13,7 +13,7 @@ import {
isLidUser
} from '../WABinary'
import { unpadRandomMax16 } from './generics'
import { ILogger } from './logger'
import type { ILogger } from './logger'
export const NO_MESSAGE_FOUND_ERROR_TEXT = 'Message absent from node'
export const MISSING_KEYS_ERROR_TEXT = 'Key used already or never filled'
@@ -62,17 +62,17 @@ export function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: strin
if (isJidUser(from) || isLidUser(from)) {
if (recipient && !isJidMetaIa(recipient)) {
if (!isMe(from) && !isMeLid(from)) {
if (!isMe(from!) && !isMeLid(from!)) {
throw new Boom('receipient present, but msg not from me', { data: stanza })
}
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')
@@ -80,30 +80,30 @@ 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'
}
chatId = from
chatId = from!
author = participant
} else if (isJidNewsletter(from)) {
msgType = 'newsletter'
chatId = from
author = from
chatId = from!
author = from!
} else {
throw new Boom('Unknown message type', { data: stanza })
}
const fromMe = (isLidUser(from) ? isMeLid : isMe)(stanza.attrs.participant || stanza.attrs.from)
const fromMe = (isLidUser(from) ? isMeLid : isMe)((stanza.attrs.participant || stanza.attrs.from)!)
const pushname = stanza?.attrs?.notify
const key: WAMessageKey = {
@@ -120,7 +120,7 @@ export function decodeMessageNode(stanza: BinaryNode, meId: string, meLid: strin
const fullMessage: WAMessage = {
key,
messageTimestamp: +stanza.attrs.t,
messageTimestamp: +stanza.attrs.t!,
pushName: pushname,
broadcast: isJidBroadcast(from)
}
@@ -221,7 +221,7 @@ export const decryptMessageNode = (
} else {
fullMessage.message = msg
}
} catch (err) {
} catch (err: any) {
logger.error({ key: fullMessage.key, err }, 'failed to decrypt message')
fullMessage.messageStubType = proto.WebMessageInfo.StubType.CIPHERTEXT
fullMessage.messageStubParameters = [err.message]