Merge pull request #2

## Summary
- Fixed TypeScript compilation errors that were preventing npm installation from git

## Changes
- **baileys-event-stream.ts**: Add null check for buffer item in priority insertion
- **baileys-logger.ts**: Handle 'silent' log level properly and fix JID sanitization with undefined checks
- **cache-utils.ts**: Fix type incompatibility in global cache by using `any` type for Map
- **logger-adapter.ts**: Add nullish coalescing for level mapping and fix console type casting
- **prometheus-metrics.ts**: Rename private `metrics` property to `metricsMap` to avoid conflict with `metrics()` method
- **trace-context.ts**: Store baggage header in variable before accessing to fix undefined check

## Test plan
- [x] `npm run build` completes successfully without TypeScript errors
- [x] Package can be installed via `npm i @whiskeysockets/baileys@git+https://github.com/rsalcara/InfiniteAPI.git#claude/fix-npm-dependency-kTdUe`
This commit is contained in:
Renato Alcara
2026-01-19 23:09:21 -03:00
committed by GitHub
8 changed files with 22323 additions and 10522 deletions
+15023
View File
File diff suppressed because it is too large Load Diff
+2 -1
View File
@@ -321,7 +321,8 @@ export class BaileysEventStream extends EventEmitter {
// Find correct position
let insertIndex = this.buffer.length
for (let i = 0; i < this.buffer.length; i++) {
if (PRIORITY_VALUES[this.buffer[i].priority] > eventPriorityValue) {
const bufferItem = this.buffer[i]
if (bufferItem && PRIORITY_VALUES[bufferItem.priority] > eventPriorityValue) {
insertIndex = i
break
}
+11 -4
View File
@@ -331,8 +331,13 @@ export class BaileysLogger implements ILogger {
...(typeof sanitizedObj === 'object' && sanitizedObj !== null ? sanitizedObj : { value: sanitizedObj }),
}
// Structured log
this.structuredLogger[level](enrichedObj, msg)
// Structured log (skip if level is 'silent')
if (level !== 'silent') {
const logMethod = this.structuredLogger[level] as ((obj: unknown, msg?: string) => void) | undefined
if (logMethod) {
logMethod.call(this.structuredLogger, enrichedObj, msg)
}
}
// Event handler
if (this.config.eventHandler) {
@@ -429,8 +434,10 @@ export class BaileysLogger implements ILogger {
if (process.env.NODE_ENV === 'production') {
// In production, mask part of the number
const parts = jid.split('@')
if (parts.length === 2 && parts[0].length > 4) {
return `${parts[0].substring(0, 4)}****@${parts[1]}`
const localPart = parts[0]
const domain = parts[1]
if (parts.length === 2 && localPart && domain && localPart.length > 4) {
return `${localPart.substring(0, 4)}****@${domain}`
}
}
return jid
+3 -2
View File
@@ -500,11 +500,12 @@ export function withCache<T extends (...args: unknown[]) => unknown>(
/**
* Global singleton cache by namespace
*/
const globalCaches: Map<string, Cache<unknown>> = new Map()
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const globalCaches: Map<string, Cache<any>> = new Map()
export function getGlobalCache<V>(namespace: string, options?: CacheOptions<V>): Cache<V> {
if (!globalCaches.has(namespace)) {
globalCaches.set(namespace, new Cache<V>({ ...options, namespace }))
globalCaches.set(namespace, new Cache<V>({ ...options, namespace }) as Cache<V>)
}
return globalCaches.get(namespace) as Cache<V>
}
+7 -3
View File
@@ -120,7 +120,7 @@ export class LoggerAdapter implements ILogger {
}
if (this.config.levelMapping && level in this.config.levelMapping) {
return this.config.levelMapping[level]
return this.config.levelMapping[level] ?? 'info'
}
return (level as LogLevel) || 'info'
@@ -327,8 +327,12 @@ function createLogMethod(
return (obj: unknown, msg?: string) => {
if (typeof logger[level] === 'function') {
;(logger[level] as (obj: unknown, msg?: string) => void)(obj, msg)
} else if (typeof (console as Record<string, unknown>)[level] === 'function') {
;(console as Record<string, (...args: unknown[]) => void>)[level](obj, msg)
} else {
// Fallback to console methods
const consoleMethod = (console as unknown as Record<string, ((...args: unknown[]) => void) | undefined>)[level]
if (typeof consoleMethod === 'function') {
consoleMethod(obj, msg)
}
}
}
}
+6 -6
View File
@@ -566,7 +566,7 @@ export class Summary implements BaseMetric {
* Metrics registry
*/
export class MetricsRegistry {
private metrics: Map<string, Counter | Gauge | Histogram | Summary> = new Map()
private metricsMap: Map<string, Counter | Gauge | Histogram | Summary> = new Map()
private prefix: string
private defaultLabels: Labels
@@ -580,7 +580,7 @@ export class MetricsRegistry {
*/
register<T extends Counter | Gauge | Histogram | Summary>(metric: T): T {
const fullName = this.prefix ? `${this.prefix}_${metric.name}` : metric.name
this.metrics.set(fullName, metric)
this.metricsMap.set(fullName, metric)
return metric
}
@@ -589,7 +589,7 @@ export class MetricsRegistry {
*/
get(name: string): Counter | Gauge | Histogram | Summary | undefined {
const fullName = this.prefix ? `${this.prefix}_${name}` : name
return this.metrics.get(fullName)
return this.metricsMap.get(fullName)
}
/**
@@ -597,14 +597,14 @@ export class MetricsRegistry {
*/
remove(name: string): boolean {
const fullName = this.prefix ? `${this.prefix}_${name}` : name
return this.metrics.delete(fullName)
return this.metricsMap.delete(fullName)
}
/**
* Reset all metrics
*/
resetAll(): void {
for (const metric of this.metrics.values()) {
for (const metric of this.metricsMap.values()) {
metric.reset()
}
}
@@ -615,7 +615,7 @@ export class MetricsRegistry {
async metrics(): Promise<string> {
const lines: string[] = []
for (const [name, metric] of this.metrics) {
for (const [name, metric] of this.metricsMap) {
lines.push(`# HELP ${name} ${metric.help}`)
lines.push(`# TYPE ${name} ${metric.type}`)
+6 -3
View File
@@ -554,11 +554,14 @@ export function extractTraceHeaders(headers: Record<string, string | undefined>)
}
// Parse baggage
if (headers[TRACE_HEADERS.BAGGAGE]) {
const baggageHeader = headers[TRACE_HEADERS.BAGGAGE]
if (baggageHeader) {
options.baggage = {}
const pairs = headers[TRACE_HEADERS.BAGGAGE].split(',')
const pairs = baggageHeader.split(',')
for (const pair of pairs) {
const [key, value] = pair.split('=')
const parts = pair.split('=')
const key = parts[0]
const value = parts[1]
if (key && value) {
options.baggage[key.trim()] = decodeURIComponent(value.trim())
}
+7265 -10503
View File
File diff suppressed because it is too large Load Diff