@hbmodsofc/baileys 1.7.7 → 2.0.0

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 (155) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/index.js +157084 -24729
  3. package/lib/Defaults/baileys-version.json +3 -0
  4. package/lib/Defaults/index.d.ts +8 -12
  5. package/lib/Defaults/index.js +124 -90
  6. package/lib/Defaults/phonenumber-mcc.json +223 -0
  7. package/lib/Signal/Group/group_cipher.d.ts +1 -0
  8. package/lib/Signal/Group/group_cipher.js +39 -28
  9. package/lib/Signal/Group/queue-job.d.ts +1 -0
  10. package/lib/Signal/Group/queue-job.js +57 -0
  11. package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
  12. package/lib/Signal/Group/sender-chain-key.js +2 -9
  13. package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
  14. package/lib/Signal/Group/sender-key-message.js +3 -3
  15. package/lib/Signal/Group/sender-key-state.d.ts +4 -4
  16. package/lib/Signal/Group/sender-key-state.js +16 -47
  17. package/lib/Signal/libsignal.d.ts +3 -7
  18. package/lib/Signal/libsignal.js +39 -224
  19. package/lib/Socket/Client/{types.d.ts → abstract-socket-client.d.ts} +3 -1
  20. package/lib/Socket/Client/index.d.ts +3 -2
  21. package/lib/Socket/Client/index.js +3 -2
  22. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  23. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  24. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  25. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +16 -10
  26. package/lib/Socket/business.d.ts +78 -94
  27. package/lib/Socket/business.js +11 -130
  28. package/lib/Socket/chats.d.ts +233 -63
  29. package/lib/Socket/chats.js +184 -234
  30. package/lib/Socket/groups.d.ts +41 -62
  31. package/lib/Socket/groups.js +64 -76
  32. package/lib/Socket/hbmods.d.ts +253 -0
  33. package/lib/Socket/hbmods.js +1 -0
  34. package/lib/Socket/index.d.ts +83 -129
  35. package/lib/Socket/index.js +6 -13
  36. package/lib/Socket/messages-recv.d.ts +48 -59
  37. package/lib/Socket/messages-recv.js +371 -516
  38. package/lib/Socket/messages-send.d.ts +67 -86
  39. package/lib/Socket/messages-send.js +1 -1091
  40. package/lib/Socket/newsletter.d.ts +64 -76
  41. package/lib/Socket/newsletter.js +1 -184
  42. package/lib/Socket/registration.d.ts +267 -0
  43. package/lib/Socket/registration.js +166 -0
  44. package/lib/Socket/socket.d.ts +13 -19
  45. package/lib/Socket/socket.js +1 -805
  46. package/lib/Socket/usync.d.ts +36 -0
  47. package/lib/Socket/usync.js +70 -0
  48. package/lib/Types/Auth.d.ts +10 -4
  49. package/lib/Types/Call.d.ts +1 -1
  50. package/lib/Types/Chat.d.ts +9 -29
  51. package/lib/Types/Chat.js +1 -7
  52. package/lib/Types/Contact.d.ts +1 -5
  53. package/lib/Types/Events.d.ts +14 -55
  54. package/lib/Types/GroupMetadata.d.ts +5 -15
  55. package/lib/Types/Label.d.ts +0 -11
  56. package/lib/Types/Label.js +1 -1
  57. package/lib/Types/LabelAssociation.js +1 -1
  58. package/lib/Types/Message.d.ts +49 -75
  59. package/lib/Types/Message.js +7 -10
  60. package/lib/Types/Newsletter.d.ts +98 -129
  61. package/lib/Types/Newsletter.js +38 -33
  62. package/lib/Types/Product.d.ts +1 -1
  63. package/lib/Types/Signal.d.ts +1 -29
  64. package/lib/Types/Socket.d.ts +22 -48
  65. package/lib/Types/State.d.ts +2 -13
  66. package/lib/Types/State.js +0 -12
  67. package/lib/Types/USync.d.ts +1 -1
  68. package/lib/Types/index.d.ts +3 -10
  69. package/lib/Types/index.js +2 -2
  70. package/lib/Utils/auth-utils.d.ts +3 -3
  71. package/lib/Utils/auth-utils.js +102 -378
  72. package/lib/Utils/baileys-event-stream.js +1 -1
  73. package/lib/Utils/business.d.ts +2 -2
  74. package/lib/Utils/business.js +13 -19
  75. package/lib/Utils/chat-utils.d.ts +22 -21
  76. package/lib/Utils/chat-utils.js +154 -201
  77. package/lib/Utils/crypto.d.ts +19 -18
  78. package/lib/Utils/crypto.js +37 -78
  79. package/lib/Utils/decode-wa-message.d.ts +7 -34
  80. package/lib/Utils/decode-wa-message.js +66 -138
  81. package/lib/Utils/event-buffer.d.ts +8 -6
  82. package/lib/Utils/event-buffer.js +43 -81
  83. package/lib/Utils/generics.d.ts +27 -27
  84. package/lib/Utils/generics.js +133 -128
  85. package/lib/Utils/history.d.ts +5 -9
  86. package/lib/Utils/history.js +23 -17
  87. package/lib/Utils/index.d.ts +0 -2
  88. package/lib/Utils/index.js +0 -2
  89. package/lib/Utils/link-preview.d.ts +4 -4
  90. package/lib/Utils/link-preview.js +12 -40
  91. package/lib/Utils/logger.d.ts +3 -11
  92. package/lib/Utils/lt-hash.d.ts +8 -8
  93. package/lib/Utils/lt-hash.js +24 -23
  94. package/lib/Utils/make-mutex.d.ts +2 -2
  95. package/lib/Utils/make-mutex.js +2 -3
  96. package/lib/Utils/messages-media.d.ts +41 -37
  97. package/lib/Utils/messages-media.js +368 -252
  98. package/lib/Utils/messages.d.ts +15 -13
  99. package/lib/Utils/messages.js +261 -274
  100. package/lib/Utils/noise-handler.d.ts +15 -13
  101. package/lib/Utils/noise-handler.js +26 -20
  102. package/lib/Utils/process-message.d.ts +8 -9
  103. package/lib/Utils/process-message.js +93 -157
  104. package/lib/Utils/signal.d.ts +5 -6
  105. package/lib/Utils/signal.js +29 -37
  106. package/lib/Utils/use-multi-file-auth-state.d.ts +2 -1
  107. package/lib/Utils/use-multi-file-auth-state.js +7 -12
  108. package/lib/Utils/validate-connection.d.ts +6 -5
  109. package/lib/Utils/validate-connection.js +97 -39
  110. package/lib/WABinary/constants.d.ts +27 -24
  111. package/lib/WABinary/constants.js +13 -1276
  112. package/lib/WABinary/decode.d.ts +4 -3
  113. package/lib/WABinary/decode.js +14 -28
  114. package/lib/WABinary/encode.d.ts +2 -1
  115. package/lib/WABinary/encode.js +147 -134
  116. package/lib/WABinary/generic-utils.d.ts +7 -4
  117. package/lib/WABinary/generic-utils.js +125 -40
  118. package/lib/WABinary/jid-utils.d.ts +8 -13
  119. package/lib/WABinary/jid-utils.js +16 -27
  120. package/lib/WAM/BinaryInfo.d.ts +11 -2
  121. package/lib/WAM/constants.d.ts +2 -3
  122. package/lib/WAM/constants.js +2359 -2252
  123. package/lib/WAM/encode.d.ts +2 -1
  124. package/lib/WAM/encode.js +11 -8
  125. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
  126. package/lib/WAUSync/Protocols/USyncContactProtocol.js +4 -3
  127. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
  128. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
  129. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
  130. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
  131. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
  132. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +6 -5
  133. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
  134. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  135. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +3 -4
  136. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +3 -11
  137. package/lib/WAUSync/USyncQuery.d.ts +2 -2
  138. package/lib/WAUSync/USyncQuery.js +15 -19
  139. package/lib/WAUSync/USyncUser.d.ts +5 -5
  140. package/lib/WAUSync/index.d.ts +1 -1
  141. package/lib/WAUSync/index.js +1 -1
  142. package/package.json +102 -102
  143. package/lib/Signal/lid-mapping.d.ts +0 -26
  144. package/lib/Signal/lid-mapping.js +0 -146
  145. package/lib/Socket/communities.d.ts +0 -232
  146. package/lib/Socket/communities.js +0 -402
  147. package/lib/Socket/mex.d.ts +0 -2
  148. package/lib/Socket/mex.js +0 -45
  149. package/lib/Types/Bussines.d.ts +0 -24
  150. package/lib/Types/Bussines.js +0 -2
  151. package/lib/Utils/lidToJid-test.d.ts +0 -11
  152. package/lib/Utils/lidToJid-test.js +0 -27
  153. package/lib/Utils/message-retry-manager.d.ts +0 -81
  154. package/lib/Utils/message-retry-manager.js +0 -152
  155. /package/lib/Socket/Client/{types.js → abstract-socket-client.js} +0 -0
@@ -1,34 +1,24 @@
1
- import type { AxiosRequestConfig } from 'axios';
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { AxiosRequestConfig } from 'axios';
2
4
  import type { Agent } from 'https';
5
+ import type { Logger } from 'pino';
3
6
  import type { URL } from 'url';
4
- import { proto } from '../../WAProto/index.js';
5
- import type { ILogger } from '../Utils/logger';
6
- import type { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth';
7
- import type { GroupMetadata } from './GroupMetadata';
8
- import { type MediaConnInfo } from './Message';
9
- import type { SignalRepositoryWithLIDStore } from './Signal';
7
+ import { proto } from '../../WAProto';
8
+ import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth';
9
+ import { MediaConnInfo } from './Message';
10
+ import { SignalRepository } from './Signal';
10
11
  export type WAVersion = [number, number, number];
11
12
  export type WABrowserDescription = [string, string, string];
12
13
  export type CacheStore = {
13
14
  /** get a cached key and change the stats */
14
- get<T>(key: string): Promise<T> | T | undefined;
15
+ get<T>(key: string): T | undefined;
15
16
  /** set a key in the cache */
16
- set<T>(key: string, value: T): Promise<void> | void | number | boolean;
17
+ set<T>(key: string, value: T): void;
17
18
  /** delete a key from the cache */
18
- del(key: string): void | Promise<void> | number | boolean;
19
+ del(key: string): void;
19
20
  /** flush all data */
20
- flushAll(): void | Promise<void>;
21
- };
22
- export type PossiblyExtendedCacheStore = CacheStore & {
23
- mget?: <T>(keys: string[]) => Promise<Record<string, T | undefined>>;
24
- mset?: <T>(entries: {
25
- key: string;
26
- value: T;
27
- }[]) => Promise<void> | void | number | boolean;
28
- mdel?: (keys: string[]) => void | Promise<void> | number | boolean;
29
- };
30
- export type PatchedMessageWithRecipientJID = proto.IMessage & {
31
- recipientJid?: string;
21
+ flushAll(): void;
32
22
  };
33
23
  export type SocketConfig = {
34
24
  /** the WS url to connect to WA */
@@ -39,24 +29,20 @@ export type SocketConfig = {
39
29
  defaultQueryTimeoutMs: number | undefined;
40
30
  /** ping-pong interval for WS connection */
41
31
  keepAliveIntervalMs: number;
42
- /** should baileys use the mobile api instead of the multi device api
43
- * @deprecated This feature has been removed
44
- */
32
+ /** should baileys use the mobile api instead of the multi device api */
45
33
  mobile?: boolean;
46
34
  /** proxy agent */
47
35
  agent?: Agent;
48
- /** logger */
49
- logger: ILogger;
36
+ /** pino logger */
37
+ logger: Logger;
50
38
  /** version to connect with */
51
39
  version: WAVersion;
52
40
  /** override browser config */
53
41
  browser: WABrowserDescription;
54
42
  /** agent used for fetch requests -- uploading/downloading media */
55
43
  fetchAgent?: Agent;
56
- /** should the QR be printed in the terminal
57
- * @deprecated This feature has been removed
58
- */
59
- printQRInTerminal?: boolean;
44
+ /** should the QR be printed in the terminal */
45
+ printQRInTerminal: boolean;
60
46
  /** should events be emitted for actions done by this socket connection */
61
47
  emitOwnEvents: boolean;
62
48
  /** custom upload hosts to upload media to */
@@ -75,8 +61,6 @@ export type SocketConfig = {
75
61
  transactionOpts: TransactionCapabilityOptions;
76
62
  /** marks the client as online whenever the socket successfully connects */
77
63
  markOnlineOnConnect: boolean;
78
- /** alphanumeric country code (USA -> US) for the number used */
79
- countryCode: string;
80
64
  /** provide a cache to store media, so does not have to be re-uploaded */
81
65
  mediaCache?: CacheStore;
82
66
  /**
@@ -84,11 +68,9 @@ export type SocketConfig = {
84
68
  * used to determine whether to retry a message or not */
85
69
  msgRetryCounterCache?: CacheStore;
86
70
  /** provide a cache to store a user's device list */
87
- userDevicesCache?: PossiblyExtendedCacheStore;
71
+ userDevicesCache?: CacheStore;
88
72
  /** cache to store call offers */
89
73
  callOfferCache?: CacheStore;
90
- /** cache to track placeholder resends */
91
- placeholderResendCache?: CacheStore;
92
74
  /** width for link preview images */
93
75
  linkPreviewImageThumbnailWidth: number;
94
76
  /** Should Baileys ask the phone for full history, will be received async */
@@ -100,10 +82,6 @@ export type SocketConfig = {
100
82
  * entails uploading the jpegThumbnail to WA
101
83
  * */
102
84
  generateHighQualityLinkPreview: boolean;
103
- /** Enable automatic session recreation for failed messages */
104
- enableAutoSessionRecreation: boolean;
105
- /** Enable recent message caching for retry handling */
106
- enableRecentMessageCache: boolean;
107
85
  /**
108
86
  * Returns if a jid should be ignored,
109
87
  * no event for that jid will be triggered.
@@ -113,7 +91,7 @@ export type SocketConfig = {
113
91
  /**
114
92
  * Optionally patch the message before sending out
115
93
  * */
116
- patchMessageBeforeSending: (msg: proto.IMessage, recipientJids?: string[]) => Promise<PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID> | PatchedMessageWithRecipientJID[] | PatchedMessageWithRecipientJID;
94
+ patchMessageBeforeSending: (msg: proto.IMessage, recipientJids: string[]) => Promise<proto.IMessage> | proto.IMessage;
117
95
  /** verify app state MACs */
118
96
  appStateMacVerification: {
119
97
  patch: boolean;
@@ -127,11 +105,7 @@ export type SocketConfig = {
127
105
  * (solves the "this message can take a while" issue) can be retried
128
106
  * */
129
107
  getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>;
130
- /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
131
- cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
132
- makeSignalRepository: (auth: SignalAuthState, onWhatsAppFunc?: (...jids: string[]) => Promise<{
133
- jid: string;
134
- exists: boolean;
135
- lid: string;
136
- }[] | undefined>) => SignalRepositoryWithLIDStore;
108
+ makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
109
+ /** Socket passthrough */
110
+ socket?: any;
137
111
  };
@@ -1,22 +1,11 @@
1
- import { Boom } from '@hapi/boom';
2
- import type { Contact } from './Contact';
3
- export declare enum SyncState {
4
- /** The socket is connecting, but we haven't received pending notifications yet. */
5
- Connecting = 0,
6
- /** Pending notifications received. Buffering events until we decide whether to sync or not. */
7
- AwaitingInitialSync = 1,
8
- /** The initial app state sync (history, etc.) is in progress. Buffering continues. */
9
- Syncing = 2,
10
- /** Initial sync is complete, or was skipped. The socket is fully operational and events are processed in real-time. */
11
- Online = 3
12
- }
1
+ import { Contact } from './Contact';
13
2
  export type WAConnectionState = 'open' | 'connecting' | 'close';
14
3
  export type ConnectionState = {
15
4
  /** connection is now open, connecting or closed */
16
5
  connection: WAConnectionState;
17
6
  /** the error that caused the connection to close */
18
7
  lastDisconnect?: {
19
- error: Boom | Error | undefined;
8
+ error: Error | undefined;
20
9
  date: Date;
21
10
  };
22
11
  /** is this a new login */
@@ -1,14 +1,2 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SyncState = void 0;
4
- var SyncState;
5
- (function (SyncState) {
6
- /** The socket is connecting, but we haven't received pending notifications yet. */
7
- SyncState[SyncState["Connecting"] = 0] = "Connecting";
8
- /** Pending notifications received. Buffering events until we decide whether to sync or not. */
9
- SyncState[SyncState["AwaitingInitialSync"] = 1] = "AwaitingInitialSync";
10
- /** The initial app state sync (history, etc.) is in progress. Buffering continues. */
11
- SyncState[SyncState["Syncing"] = 2] = "Syncing";
12
- /** Initial sync is complete, or was skipped. The socket is fully operational and events are processed in real-time. */
13
- SyncState[SyncState["Online"] = 3] = "Online";
14
- })(SyncState || (exports.SyncState = SyncState = {}));
@@ -1,4 +1,4 @@
1
- import type { BinaryNode } from '../WABinary';
1
+ import { BinaryNode } from '../WABinary';
2
2
  import { USyncUser } from '../WAUSync';
3
3
  /**
4
4
  * Defines the interface for a USyncQuery protocol
@@ -4,24 +4,17 @@ export * from './Chat';
4
4
  export * from './Contact';
5
5
  export * from './State';
6
6
  export * from './Message';
7
+ export * from './Newsletter';
7
8
  export * from './Socket';
8
9
  export * from './Events';
9
10
  export * from './Product';
10
11
  export * from './Call';
11
12
  export * from './Signal';
12
- export * from './Newsletter';
13
- import type { AuthenticationState } from './Auth';
14
- import type { SocketConfig } from './Socket';
13
+ import { AuthenticationState } from './Auth';
14
+ import { SocketConfig } from './Socket';
15
15
  export type UserFacingSocketConfig = Partial<SocketConfig> & {
16
16
  auth: AuthenticationState;
17
17
  };
18
- export type BrowsersMap = {
19
- ubuntu(browser: string): [string, string, string];
20
- macOS(browser: string): [string, string, string];
21
- baileys(browser: string): [string, string, string];
22
- windows(browser: string): [string, string, string];
23
- appropriate(browser: string): [string, string, string];
24
- };
25
18
  export declare enum DisconnectReason {
26
19
  connectionClosed = 428,
27
20
  connectionLost = 408,
@@ -21,12 +21,12 @@ __exportStar(require("./Chat"), exports);
21
21
  __exportStar(require("./Contact"), exports);
22
22
  __exportStar(require("./State"), exports);
23
23
  __exportStar(require("./Message"), exports);
24
+ __exportStar(require("./Newsletter"), exports);
24
25
  __exportStar(require("./Socket"), exports);
25
26
  __exportStar(require("./Events"), exports);
26
27
  __exportStar(require("./Product"), exports);
27
28
  __exportStar(require("./Call"), exports);
28
29
  __exportStar(require("./Signal"), exports);
29
- __exportStar(require("./Newsletter"), exports);
30
30
  var DisconnectReason;
31
31
  (function (DisconnectReason) {
32
32
  DisconnectReason[DisconnectReason["connectionClosed"] = 428] = "connectionClosed";
@@ -39,4 +39,4 @@ var DisconnectReason;
39
39
  DisconnectReason[DisconnectReason["multideviceMismatch"] = 411] = "multideviceMismatch";
40
40
  DisconnectReason[DisconnectReason["forbidden"] = 403] = "forbidden";
41
41
  DisconnectReason[DisconnectReason["unavailableService"] = 503] = "unavailableService";
42
- })(DisconnectReason || (exports.DisconnectReason = DisconnectReason = {}));
42
+ })(DisconnectReason = exports.DisconnectReason || (exports.DisconnectReason = {}));
@@ -1,12 +1,12 @@
1
+ import type { Logger } from 'pino';
1
2
  import type { AuthenticationCreds, CacheStore, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types';
2
- import type { ILogger } from './logger';
3
3
  /**
4
4
  * Adds caching capability to a SignalKeyStore
5
5
  * @param store the store to add caching to
6
6
  * @param logger to log trace events
7
7
  * @param _cache cache store to use
8
8
  */
9
- export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger?: ILogger, _cache?: CacheStore): SignalKeyStore;
9
+ export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger: Logger, _cache?: CacheStore): SignalKeyStore;
10
10
  /**
11
11
  * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
12
12
  * this allows batch read & write operations & improves the performance of the lib
@@ -14,5 +14,5 @@ export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logge
14
14
  * @param logger logger to log events
15
15
  * @returns SignalKeyStore with transaction capability
16
16
  */
17
- export declare const addTransactionCapability: (state: SignalKeyStore, logger: ILogger, { maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions) => SignalKeyStoreWithTransaction;
17
+ export declare const addTransactionCapability: (state: SignalKeyStore, logger: Logger, { maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions) => SignalKeyStoreWithTransaction;
18
18
  export declare const initAuthCreds: () => AuthenticationCreds;