@skycodee/baileys 8.0.2 → 8.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/package.json +14 -44
  2. package/src/Defaults/baileys-version.json +0 -1
  3. package/src/Defaults/index.ts +0 -149
  4. package/src/Signal/Group/ciphertext-message.ts +0 -9
  5. package/src/Signal/Group/group-session-builder.ts +0 -56
  6. package/src/Signal/Group/group_cipher.ts +0 -117
  7. package/src/Signal/Group/index.ts +0 -11
  8. package/src/Signal/Group/keyhelper.ts +0 -28
  9. package/src/Signal/Group/sender-chain-key.ts +0 -34
  10. package/src/Signal/Group/sender-key-distribution-message.ts +0 -95
  11. package/src/Signal/Group/sender-key-message.ts +0 -96
  12. package/src/Signal/Group/sender-key-name.ts +0 -66
  13. package/src/Signal/Group/sender-key-record.ts +0 -69
  14. package/src/Signal/Group/sender-key-state.ts +0 -134
  15. package/src/Signal/Group/sender-message-key.ts +0 -36
  16. package/src/Signal/libsignal.ts +0 -521
  17. package/src/Signal/lid-mapping.ts +0 -328
  18. package/src/Socket/Client/index.ts +0 -2
  19. package/src/Socket/Client/types.ts +0 -22
  20. package/src/Socket/Client/websocket.ts +0 -63
  21. package/src/Socket/business.ts +0 -424
  22. package/src/Socket/chats.ts +0 -1272
  23. package/src/Socket/communities.ts +0 -477
  24. package/src/Socket/groups.ts +0 -361
  25. package/src/Socket/index.ts +0 -15
  26. package/src/Socket/messages-recv.ts +0 -1668
  27. package/src/Socket/messages-send.ts +0 -1296
  28. package/src/Socket/mex.ts +0 -58
  29. package/src/Socket/newsletter.ts +0 -229
  30. package/src/Socket/socket.ts +0 -1184
  31. package/src/Types/Auth.ts +0 -116
  32. package/src/Types/Bussines.ts +0 -20
  33. package/src/Types/Call.ts +0 -15
  34. package/src/Types/Chat.ts +0 -138
  35. package/src/Types/Contact.ts +0 -24
  36. package/src/Types/Events.ts +0 -159
  37. package/src/Types/GroupMetadata.ts +0 -70
  38. package/src/Types/Label.ts +0 -48
  39. package/src/Types/LabelAssociation.ts +0 -35
  40. package/src/Types/Message.ts +0 -380
  41. package/src/Types/Newsletter.ts +0 -98
  42. package/src/Types/Product.ts +0 -85
  43. package/src/Types/Signal.ts +0 -76
  44. package/src/Types/Socket.ts +0 -150
  45. package/src/Types/State.ts +0 -43
  46. package/src/Types/USync.ts +0 -27
  47. package/src/Types/globals.d.ts +0 -8
  48. package/src/Types/index.ts +0 -67
  49. package/src/Utils/auth-utils.ts +0 -368
  50. package/src/Utils/browser-utils.ts +0 -31
  51. package/src/Utils/business.ts +0 -286
  52. package/src/Utils/chat-utils.ts +0 -974
  53. package/src/Utils/crypto.ts +0 -147
  54. package/src/Utils/decode-wa-message.ts +0 -355
  55. package/src/Utils/event-buffer.ts +0 -692
  56. package/src/Utils/generics.ts +0 -474
  57. package/src/Utils/history.ts +0 -161
  58. package/src/Utils/identity-change-handler.ts +0 -83
  59. package/src/Utils/index.ts +0 -19
  60. package/src/Utils/link-preview.ts +0 -111
  61. package/src/Utils/logger.ts +0 -13
  62. package/src/Utils/lt-hash.ts +0 -8
  63. package/src/Utils/make-mutex.ts +0 -42
  64. package/src/Utils/message-retry-manager.ts +0 -295
  65. package/src/Utils/messages-media.ts +0 -984
  66. package/src/Utils/messages.ts +0 -1097
  67. package/src/Utils/noise-handler.ts +0 -268
  68. package/src/Utils/pre-key-manager.ts +0 -126
  69. package/src/Utils/process-message.ts +0 -670
  70. package/src/Utils/reporting-utils.ts +0 -344
  71. package/src/Utils/signal.ts +0 -214
  72. package/src/Utils/sync-action-utils.ts +0 -74
  73. package/src/Utils/tc-token-utils.ts +0 -34
  74. package/src/Utils/use-multi-file-auth-state.ts +0 -136
  75. package/src/Utils/validate-connection.ts +0 -253
  76. package/src/WABinary/constants.ts +0 -1305
  77. package/src/WABinary/decode.ts +0 -308
  78. package/src/WABinary/encode.ts +0 -258
  79. package/src/WABinary/generic-utils.ts +0 -141
  80. package/src/WABinary/index.ts +0 -5
  81. package/src/WABinary/jid-utils.ts +0 -128
  82. package/src/WABinary/types.ts +0 -17
  83. package/src/WAM/BinaryInfo.ts +0 -12
  84. package/src/WAM/constants.ts +0 -22889
  85. package/src/WAM/encode.ts +0 -169
  86. package/src/WAM/index.ts +0 -3
  87. package/src/WAUSync/Protocols/USyncContactProtocol.ts +0 -32
  88. package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +0 -78
  89. package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +0 -35
  90. package/src/WAUSync/Protocols/USyncStatusProtocol.ts +0 -44
  91. package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +0 -76
  92. package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +0 -33
  93. package/src/WAUSync/Protocols/index.ts +0 -4
  94. package/src/WAUSync/USyncQuery.ts +0 -133
  95. package/src/WAUSync/USyncUser.ts +0 -32
  96. package/src/WAUSync/index.ts +0 -3
  97. package/src/__tests__/Signal/Group/sender-key-state-regression.test.ts +0 -22
  98. package/src/__tests__/Signal/lid-mapping.test.ts +0 -47
  99. package/src/__tests__/Socket/identity-change-handling.test.ts +0 -207
  100. package/src/__tests__/TestUtils/session.ts +0 -47
  101. package/src/__tests__/Utils/generics.test.ts +0 -70
  102. package/src/__tests__/Utils/history.test.ts +0 -362
  103. package/src/__tests__/Utils/messages-media.test.ts +0 -405
  104. package/src/__tests__/Utils/noise-handler.test.ts +0 -339
  105. package/src/__tests__/Utils/process-message.test.ts +0 -138
  106. package/src/__tests__/Utils/process-sync-action.test.ts +0 -359
  107. package/src/__tests__/Utils/reporting-utils.test.ts +0 -160
  108. package/src/__tests__/Utils/signal.test.ts +0 -69
  109. package/src/__tests__/Utils/sync-action-utils.test.ts +0 -183
  110. package/src/__tests__/binary/connection-deadlock.test.ts +0 -54
  111. package/src/__tests__/e2e/fetch-wa-web-version.test-e2e.ts +0 -60
  112. package/src/__tests__/e2e/send-receive-message.test-e2e.ts +0 -644
  113. package/src/__tests__/proto-tojson-long.test.ts +0 -31
  114. package/src/index.ts +0 -13
@@ -1,183 +0,0 @@
1
- import { jest } from '@jest/globals'
2
- import type { ILogger } from '../../Utils/logger'
3
- import { processContactAction } from '../../Utils/sync-action-utils'
4
-
5
- describe('processContactAction', () => {
6
- const mockLogger: ILogger = {
7
- warn: jest.fn(),
8
- info: jest.fn(),
9
- debug: jest.fn(),
10
- error: jest.fn(),
11
- trace: jest.fn(),
12
- child: jest.fn(() => mockLogger),
13
- level: 'silent'
14
- } as unknown as ILogger
15
-
16
- beforeEach(() => {
17
- jest.clearAllMocks()
18
- })
19
-
20
- describe('contacts.upsert', () => {
21
- it('emits with phoneNumber from id when id is PN user', () => {
22
- const action = { fullName: 'John Doe', lidJid: '123456789@lid', pnJid: null }
23
- const id = '5511999999999@s.whatsapp.net'
24
-
25
- const results = processContactAction(action, id)
26
-
27
- expect(results).toContainEqual({
28
- event: 'contacts.upsert',
29
- data: [
30
- {
31
- id: '5511999999999@s.whatsapp.net',
32
- name: 'John Doe',
33
- lid: '123456789@lid',
34
- phoneNumber: '5511999999999@s.whatsapp.net'
35
- }
36
- ]
37
- })
38
- })
39
-
40
- it('uses pnJid as phoneNumber fallback when id is LID user', () => {
41
- const action = { fullName: 'John Doe', lidJid: null, pnJid: '5511888888888@s.whatsapp.net' }
42
- const id = '123456789@lid'
43
-
44
- const results = processContactAction(action, id)
45
-
46
- expect(results).toContainEqual({
47
- event: 'contacts.upsert',
48
- data: [
49
- {
50
- id: '123456789@lid',
51
- name: 'John Doe',
52
- lid: undefined,
53
- phoneNumber: '5511888888888@s.whatsapp.net'
54
- }
55
- ]
56
- })
57
- })
58
-
59
- it('handles undefined fullName', () => {
60
- const action = { fullName: undefined, lidJid: '123456789@lid', pnJid: null }
61
- const id = '5511999999999@s.whatsapp.net'
62
-
63
- const results = processContactAction(action, id)
64
-
65
- const contactData = results.find(r => r.event === 'contacts.upsert')!.data
66
- expect(contactData[0]!.name).toBeUndefined()
67
- })
68
- })
69
-
70
- describe('lid-mapping.update', () => {
71
- it('emits when LID and PN are valid', () => {
72
- const action = { fullName: 'John Doe', lidJid: '123456789@lid', pnJid: null }
73
- const id = '5511999999999@s.whatsapp.net'
74
-
75
- const results = processContactAction(action, id)
76
-
77
- expect(results).toContainEqual({
78
- event: 'lid-mapping.update',
79
- data: { lid: '123456789@lid', pn: '5511999999999@s.whatsapp.net' }
80
- })
81
- })
82
-
83
- it('handles LID with device ID suffix', () => {
84
- const action = { fullName: 'Contact', lidJid: '173233882013816:99@lid', pnJid: null }
85
- const id = '5511999999999@s.whatsapp.net'
86
-
87
- const results = processContactAction(action, id)
88
-
89
- expect(results).toContainEqual({
90
- event: 'lid-mapping.update',
91
- data: { lid: '173233882013816:99@lid', pn: '5511999999999@s.whatsapp.net' }
92
- })
93
- })
94
-
95
- it('does NOT emit when lidJid is missing', () => {
96
- const action = { fullName: 'John Doe', lidJid: null, pnJid: null }
97
- const id = '5511999999999@s.whatsapp.net'
98
-
99
- const results = processContactAction(action, id)
100
-
101
- expect(results.find(r => r.event === 'lid-mapping.update')).toBeUndefined()
102
- })
103
-
104
- it('does NOT emit when id is LID user (not PN)', () => {
105
- const action = { fullName: 'John Doe', lidJid: '123456789@lid', pnJid: null }
106
- const id = '987654321@lid'
107
-
108
- const results = processContactAction(action, id)
109
-
110
- expect(results.find(r => r.event === 'lid-mapping.update')).toBeUndefined()
111
- })
112
-
113
- it('does NOT emit when lidJid is invalid format', () => {
114
- const action = { fullName: 'John Doe', lidJid: 'invalid-lid-format', pnJid: null }
115
- const id = '5511999999999@s.whatsapp.net'
116
-
117
- const results = processContactAction(action, id)
118
-
119
- expect(results.find(r => r.event === 'lid-mapping.update')).toBeUndefined()
120
- })
121
-
122
- it('does NOT emit for group JIDs', () => {
123
- const action = { fullName: 'Group', lidJid: '123456789@lid', pnJid: null }
124
- const id = '123456789012345678@g.us'
125
-
126
- const results = processContactAction(action, id)
127
-
128
- expect(results.find(r => r.event === 'lid-mapping.update')).toBeUndefined()
129
- })
130
- })
131
-
132
- describe('missing id', () => {
133
- it('returns empty array and logs warning when id is undefined', () => {
134
- const action = { fullName: 'John Doe', lidJid: '123456789@lid', pnJid: null }
135
-
136
- const results = processContactAction(action, undefined, mockLogger)
137
-
138
- expect(results).toEqual([])
139
- expect(mockLogger.warn).toHaveBeenCalledWith(
140
- { hasFullName: true, hasLidJid: true, hasPnJid: false },
141
- 'contactAction sync: missing id in index'
142
- )
143
- })
144
-
145
- it('returns empty array when id is empty string', () => {
146
- const action = { fullName: 'John Doe', lidJid: '123456789@lid', pnJid: null }
147
-
148
- const results = processContactAction(action, '', mockLogger)
149
-
150
- expect(results).toEqual([])
151
- })
152
- })
153
-
154
- describe('PN extraction from index[1] (pnJid is always null)', () => {
155
- it('extracts PN from id when pnJid is null', () => {
156
- // In real WhatsApp data, pnJid is ALWAYS null - PN comes from index[1]
157
- const action = { fullName: 'Test Contact', lidJid: '111222333@lid', pnJid: null }
158
- const id = '5599887766@s.whatsapp.net'
159
-
160
- const results = processContactAction(action, id)
161
-
162
- const contactData = results.find(r => r.event === 'contacts.upsert')!.data
163
- expect(contactData[0]!.phoneNumber).toBe('5599887766@s.whatsapp.net')
164
- expect(contactData[0]!.lid).toBe('111222333@lid')
165
-
166
- const mapping = results.find(r => r.event === 'lid-mapping.update')!.data
167
- expect(mapping).toEqual({ lid: '111222333@lid', pn: '5599887766@s.whatsapp.net' })
168
- })
169
-
170
- it('prefers id over pnJid when id is PN user', () => {
171
- const action = { fullName: 'Test', lidJid: '111222333@lid', pnJid: '1111111111@s.whatsapp.net' }
172
- const id = '9999999999@s.whatsapp.net'
173
-
174
- const results = processContactAction(action, id)
175
-
176
- const contactData = results.find(r => r.event === 'contacts.upsert')!.data
177
- expect(contactData[0]!.phoneNumber).toBe('9999999999@s.whatsapp.net')
178
-
179
- const mapping = results.find(r => r.event === 'lid-mapping.update')!.data
180
- expect(mapping.pn).toBe('9999999999@s.whatsapp.net')
181
- })
182
- })
183
- })
@@ -1,54 +0,0 @@
1
- import { jest } from '@jest/globals'
2
- import { proto, type WAMessage } from '../..'
3
- import { DEFAULT_CONNECTION_CONFIG } from '../../Defaults'
4
- import makeWASocket from '../../Socket'
5
- import { makeSession, mockWebSocket } from '../TestUtils/session'
6
-
7
- mockWebSocket()
8
-
9
- describe('Connection Deadlock Test', () => {
10
- it('should not deadlock when history sync is disabled', async () => {
11
- const { state, clear } = await makeSession()
12
-
13
- state.creds.me = { id: '1234567890:1@s.whatsapp.net', name: 'Test User' }
14
-
15
- const sock = makeWASocket({
16
- ...DEFAULT_CONNECTION_CONFIG,
17
- auth: state,
18
- shouldSyncHistoryMessage: () => false
19
- })
20
-
21
- const regularMessageListener = jest.fn()
22
- sock.ev.on('messages.upsert', regularMessageListener)
23
-
24
- // 1. Simulate receiving pending notifications. This activates the buffer.
25
- sock.ev.emit('connection.update', { receivedPendingNotifications: true })
26
-
27
- // 2. Now, emit a regular message. Because the previous step should have
28
- // flushed the buffer, this message should be processed immediately.
29
- const regularMessage = proto.WebMessageInfo.fromObject({
30
- key: { remoteJid: '1234567890@s.whatsapp.net', fromMe: false, id: 'REGULAR_MSG_1' },
31
- messageTimestamp: Date.now() / 1000,
32
- message: { conversation: 'Hello, world!' }
33
- }) as WAMessage
34
- sock.ev.emit('messages.upsert', { messages: [regularMessage], type: 'notify' })
35
- // Wait for the event loop to process any final events.
36
- await new Promise(resolve => setTimeout(resolve, 50))
37
-
38
- // 3. Check if the regular message listener was called.
39
- expect(regularMessageListener).toHaveBeenCalledTimes(1)
40
- expect(regularMessageListener).toHaveBeenCalledWith(
41
- expect.objectContaining({
42
- messages: expect.arrayContaining([
43
- expect.objectContaining({
44
- key: regularMessage.key
45
- })
46
- ]),
47
- type: 'notify'
48
- })
49
- )
50
-
51
- await sock.end(new Error('Test completed'))
52
- await clear()
53
- })
54
- })
@@ -1,60 +0,0 @@
1
- import { jest } from '@jest/globals'
2
- import { fetchLatestWaWebVersion } from '../../Utils/generics'
3
-
4
- describe('fetchLatestWaWebVersion Integration Tests', () => {
5
- jest.setTimeout(10000)
6
-
7
- it('should successfully fetch the latest WhatsApp Web version from real API', async () => {
8
- const result = await fetchLatestWaWebVersion()
9
-
10
- expect(Array.isArray(result.version)).toBe(true)
11
- expect(result.version).toHaveLength(3)
12
- expect(typeof result.version[0]).toBe('number')
13
- expect(typeof result.version[1]).toBe('number')
14
- expect(typeof result.version[2]).toBe('number')
15
-
16
- expect(typeof result.isLatest).toBe('boolean')
17
-
18
- if (!result.isLatest) {
19
- expect(result.error).toBeDefined()
20
- }
21
- })
22
-
23
- it('should handle custom headers correctly', async () => {
24
- const customHeaders = {
25
- accept:
26
- 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
27
- 'accept-language': 'en-US,en;q=0.9',
28
- 'cache-control': 'max-age=0',
29
- 'sec-ch-prefers-color-scheme': 'dark',
30
- 'sec-fetch-dest': 'document',
31
- 'sec-fetch-mode': 'navigate',
32
- 'sec-fetch-site': 'none',
33
- 'upgrade-insecure-requests': '1'
34
- }
35
-
36
- const result = await fetchLatestWaWebVersion({
37
- headers: customHeaders
38
- })
39
-
40
- expect(Array.isArray(result.version)).toBe(true)
41
- expect(result.version).toHaveLength(3)
42
- expect(result.isLatest).toBe(true)
43
- })
44
-
45
- it('should fallback gracefully when client_revision is not found', async () => {
46
- const result = await fetchLatestWaWebVersion()
47
-
48
- expect(result).toHaveProperty('version')
49
- expect(result).toHaveProperty('isLatest')
50
- expect(Array.isArray(result.version)).toBe(true)
51
- })
52
-
53
- it('should handle network timeouts gracefully', async () => {
54
- const result = await fetchLatestWaWebVersion()
55
-
56
- expect(result).toHaveProperty('version')
57
- expect(result).toHaveProperty('isLatest')
58
- expect(Array.isArray(result.version)).toBe(true)
59
- })
60
- })