gifted-baileys 1.5.5 → 1.5.7

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 (251) hide show
  1. package/README.md +6 -1642
  2. package/WAProto/WAProto.proto +969 -88
  3. package/WAProto/index.d.ts +13199 -1260
  4. package/WAProto/index.js +124901 -74525
  5. package/lib/Defaults/baileys-version.json +3 -0
  6. package/lib/Defaults/index.d.ts +284 -0
  7. package/{src → lib}/Defaults/index.js +7 -14
  8. package/lib/Signal/libsignal.d.ts +3 -0
  9. package/lib/Signal/libsignal.js +161 -0
  10. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  11. package/lib/Socket/Client/index.d.ts +2 -0
  12. package/{src → lib}/Socket/Client/index.js +2 -3
  13. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  14. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  15. package/lib/Socket/Client/types.d.ts +17 -0
  16. package/lib/Socket/Client/types.js +13 -0
  17. package/lib/Socket/Client/websocket.d.ts +12 -0
  18. package/lib/Socket/Client/websocket.js +62 -0
  19. package/lib/Socket/business.d.ts +170 -0
  20. package/{src → lib}/Socket/business.js +28 -33
  21. package/lib/Socket/chats.d.ts +81 -0
  22. package/{src → lib}/Socket/chats.js +174 -176
  23. package/lib/Socket/groups.d.ts +115 -0
  24. package/{src → lib}/Socket/groups.js +80 -68
  25. package/lib/Socket/index.d.ts +172 -0
  26. package/{src → lib}/Socket/index.js +4 -1
  27. package/lib/Socket/messages-recv.d.ts +158 -0
  28. package/{src → lib}/Socket/messages-recv.js +378 -211
  29. package/lib/Socket/messages-send.d.ts +155 -0
  30. package/{src → lib}/Socket/messages-send.js +452 -177
  31. package/lib/Socket/newsletter.d.ts +132 -0
  32. package/{src → lib}/Socket/newsletter.js +107 -98
  33. package/lib/Socket/registration.d.ts +264 -0
  34. package/{src → lib}/Socket/registration.js +56 -48
  35. package/lib/Socket/socket.d.ts +44 -0
  36. package/{src → lib}/Socket/socket.js +77 -77
  37. package/lib/Socket/usync.d.ts +37 -0
  38. package/lib/Socket/usync.js +70 -0
  39. package/lib/Store/index.d.ts +3 -0
  40. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  41. package/{src → lib}/Store/make-cache-manager-store.js +25 -34
  42. package/lib/Store/make-in-memory-store.d.ts +118 -0
  43. package/{src → lib}/Store/make-in-memory-store.js +36 -32
  44. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  45. package/lib/Store/object-repository.d.ts +10 -0
  46. package/{src → lib}/Store/object-repository.js +1 -1
  47. package/lib/Types/Auth.d.ts +109 -0
  48. package/lib/Types/Call.d.ts +13 -0
  49. package/lib/Types/Chat.d.ts +107 -0
  50. package/{src/Types/Contact.ts → lib/Types/Contact.d.ts} +8 -9
  51. package/lib/Types/Events.d.ts +172 -0
  52. package/lib/Types/GroupMetadata.d.ts +56 -0
  53. package/lib/Types/Label.d.ts +46 -0
  54. package/{src/Types/LabelAssociation.ts → lib/Types/LabelAssociation.d.ts} +16 -22
  55. package/lib/Types/Message.d.ts +433 -0
  56. package/lib/Types/Newsletter.d.ts +92 -0
  57. package/lib/Types/Product.d.ts +78 -0
  58. package/lib/Types/Signal.d.ts +57 -0
  59. package/{src/Types/Socket.ts → lib/Types/Socket.d.ts} +61 -68
  60. package/lib/Types/State.d.ts +27 -0
  61. package/lib/Types/USync.d.ts +25 -0
  62. package/lib/Types/index.d.ts +66 -0
  63. package/lib/Utils/auth-utils.d.ts +18 -0
  64. package/{src → lib}/Utils/auth-utils.js +73 -90
  65. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  66. package/lib/Utils/baileys-event-stream.js +63 -0
  67. package/lib/Utils/business.d.ts +22 -0
  68. package/{src → lib}/Utils/business.js +15 -43
  69. package/lib/Utils/chat-utils.d.ts +70 -0
  70. package/{src → lib}/Utils/chat-utils.js +87 -94
  71. package/lib/Utils/crypto.d.ts +40 -0
  72. package/{src → lib}/Utils/crypto.js +4 -2
  73. package/lib/Utils/decode-wa-message.d.ts +36 -0
  74. package/lib/Utils/decode-wa-message.js +226 -0
  75. package/lib/Utils/event-buffer.d.ts +35 -0
  76. package/{src → lib}/Utils/event-buffer.js +4 -13
  77. package/lib/Utils/generics.d.ts +88 -0
  78. package/{src → lib}/Utils/generics.js +67 -86
  79. package/lib/Utils/history.d.ts +19 -0
  80. package/{src → lib}/Utils/history.js +13 -39
  81. package/lib/Utils/index.d.ts +17 -0
  82. package/lib/Utils/link-preview.d.ts +21 -0
  83. package/{src → lib}/Utils/link-preview.js +17 -54
  84. package/lib/Utils/logger.d.ts +2 -0
  85. package/lib/Utils/lt-hash.d.ts +12 -0
  86. package/lib/Utils/make-mutex.d.ts +7 -0
  87. package/{src → lib}/Utils/make-mutex.js +4 -13
  88. package/lib/Utils/messages-media.d.ts +113 -0
  89. package/{src → lib}/Utils/messages-media.js +193 -255
  90. package/lib/Utils/messages.d.ts +77 -0
  91. package/{src → lib}/Utils/messages.js +588 -118
  92. package/lib/Utils/noise-handler.d.ts +20 -0
  93. package/lib/Utils/process-message.d.ts +41 -0
  94. package/{src → lib}/Utils/process-message.js +27 -30
  95. package/lib/Utils/signal.d.ts +33 -0
  96. package/{src → lib}/Utils/signal.js +25 -42
  97. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  98. package/{src → lib}/Utils/use-multi-file-auth-state.js +27 -28
  99. package/lib/Utils/validate-connection.d.ts +11 -0
  100. package/{src → lib}/Utils/validate-connection.js +40 -9
  101. package/lib/WABinary/constants.d.ts +27 -0
  102. package/lib/WABinary/decode.d.ts +6 -0
  103. package/lib/WABinary/encode.d.ts +2 -0
  104. package/{src → lib}/WABinary/encode.js +16 -10
  105. package/lib/WABinary/generic-utils.d.ts +14 -0
  106. package/lib/WABinary/index.d.ts +5 -0
  107. package/lib/WABinary/jid-utils.d.ts +31 -0
  108. package/lib/WABinary/types.d.ts +18 -0
  109. package/lib/WABinary/types.js +2 -0
  110. package/lib/WAM/BinaryInfo.d.ts +8 -0
  111. package/lib/WAM/constants.d.ts +38 -0
  112. package/lib/WAM/encode.d.ts +2 -0
  113. package/lib/WAM/index.d.ts +3 -0
  114. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  115. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  116. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  117. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  118. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  119. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  120. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  121. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  122. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  123. package/lib/WAUSync/Protocols/index.js +20 -0
  124. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  125. package/lib/WAUSync/USyncQuery.js +79 -0
  126. package/lib/WAUSync/USyncUser.d.ts +10 -0
  127. package/lib/WAUSync/USyncUser.js +22 -0
  128. package/lib/WAUSync/index.d.ts +3 -0
  129. package/lib/WAUSync/index.js +19 -0
  130. package/{src → lib}/index.js +1 -0
  131. package/package.json +26 -8
  132. package/LICENSE +0 -21
  133. package/src/Defaults/baileys-version.json +0 -3
  134. package/src/Defaults/index.ts +0 -131
  135. package/src/Signal/libsignal.js +0 -180
  136. package/src/Signal/libsignal.ts +0 -141
  137. package/src/Socket/Client/abstract-socket-client.ts +0 -19
  138. package/src/Socket/Client/index.ts +0 -3
  139. package/src/Socket/Client/mobile-socket-client.js +0 -78
  140. package/src/Socket/Client/mobile-socket-client.ts +0 -66
  141. package/src/Socket/Client/web-socket-client.js +0 -75
  142. package/src/Socket/Client/web-socket-client.ts +0 -57
  143. package/src/Socket/business.ts +0 -281
  144. package/src/Socket/chats.ts +0 -1030
  145. package/src/Socket/groups.ts +0 -356
  146. package/src/Socket/index.ts +0 -13
  147. package/src/Socket/messages-recv.ts +0 -985
  148. package/src/Socket/messages-send.ts +0 -871
  149. package/src/Socket/newsletter.ts +0 -282
  150. package/src/Socket/registration.ts +0 -250
  151. package/src/Socket/socket.ts +0 -777
  152. package/src/Store/index.ts +0 -3
  153. package/src/Store/make-cache-manager-store.ts +0 -100
  154. package/src/Store/make-in-memory-store.ts +0 -475
  155. package/src/Store/make-ordered-dictionary.ts +0 -86
  156. package/src/Store/object-repository.ts +0 -32
  157. package/src/Tests/test.app-state-sync.js +0 -204
  158. package/src/Tests/test.app-state-sync.ts +0 -207
  159. package/src/Tests/test.event-buffer.js +0 -270
  160. package/src/Tests/test.event-buffer.ts +0 -319
  161. package/src/Tests/test.key-store.js +0 -76
  162. package/src/Tests/test.key-store.ts +0 -92
  163. package/src/Tests/test.libsignal.js +0 -141
  164. package/src/Tests/test.libsignal.ts +0 -186
  165. package/src/Tests/test.media-download.js +0 -93
  166. package/src/Tests/test.media-download.ts +0 -76
  167. package/src/Tests/test.messages.js +0 -33
  168. package/src/Tests/test.messages.ts +0 -37
  169. package/src/Tests/utils.js +0 -34
  170. package/src/Tests/utils.ts +0 -36
  171. package/src/Types/Auth.ts +0 -113
  172. package/src/Types/Call.ts +0 -15
  173. package/src/Types/Chat.ts +0 -106
  174. package/src/Types/Events.ts +0 -93
  175. package/src/Types/GroupMetadata.ts +0 -53
  176. package/src/Types/Label.ts +0 -36
  177. package/src/Types/Message.ts +0 -288
  178. package/src/Types/Newsletter.ts +0 -98
  179. package/src/Types/Product.ts +0 -85
  180. package/src/Types/Signal.ts +0 -68
  181. package/src/Types/State.ts +0 -29
  182. package/src/Types/index.ts +0 -59
  183. package/src/Utils/auth-utils.ts +0 -222
  184. package/src/Utils/baileys-event-stream.js +0 -92
  185. package/src/Utils/baileys-event-stream.ts +0 -66
  186. package/src/Utils/business.ts +0 -275
  187. package/src/Utils/chat-utils.ts +0 -860
  188. package/src/Utils/crypto.ts +0 -131
  189. package/src/Utils/decode-wa-message.js +0 -211
  190. package/src/Utils/decode-wa-message.ts +0 -228
  191. package/src/Utils/event-buffer.ts +0 -613
  192. package/src/Utils/generics.ts +0 -434
  193. package/src/Utils/history.ts +0 -112
  194. package/src/Utils/index.ts +0 -17
  195. package/src/Utils/link-preview.ts +0 -122
  196. package/src/Utils/logger.ts +0 -3
  197. package/src/Utils/lt-hash.ts +0 -61
  198. package/src/Utils/make-mutex.ts +0 -44
  199. package/src/Utils/messages-media.ts +0 -847
  200. package/src/Utils/messages.ts +0 -956
  201. package/src/Utils/noise-handler.ts +0 -197
  202. package/src/Utils/process-message.ts +0 -414
  203. package/src/Utils/signal.ts +0 -177
  204. package/src/Utils/use-multi-file-auth-state.ts +0 -90
  205. package/src/Utils/validate-connection.ts +0 -238
  206. package/src/WABinary/constants.ts +0 -42
  207. package/src/WABinary/decode.ts +0 -265
  208. package/src/WABinary/encode.ts +0 -236
  209. package/src/WABinary/generic-utils.ts +0 -121
  210. package/src/WABinary/index.ts +0 -5
  211. package/src/WABinary/jid-utils.ts +0 -68
  212. package/src/WABinary/types.ts +0 -17
  213. package/src/WAM/BinaryInfo.ts +0 -12
  214. package/src/WAM/constants.ts +0 -15382
  215. package/src/WAM/encode.ts +0 -174
  216. package/src/WAM/index.ts +0 -3
  217. package/src/gifted +0 -1
  218. package/src/index.ts +0 -13
  219. /package/{src → lib}/Defaults/phonenumber-mcc.json +0 -0
  220. /package/{src → lib}/Socket/Client/abstract-socket-client.js +0 -0
  221. /package/{src → lib}/Store/index.js +0 -0
  222. /package/{src → lib}/Store/make-ordered-dictionary.js +0 -0
  223. /package/{src → lib}/Types/Auth.js +0 -0
  224. /package/{src → lib}/Types/Call.js +0 -0
  225. /package/{src → lib}/Types/Chat.js +0 -0
  226. /package/{src → lib}/Types/Contact.js +0 -0
  227. /package/{src → lib}/Types/Events.js +0 -0
  228. /package/{src → lib}/Types/GroupMetadata.js +0 -0
  229. /package/{src → lib}/Types/Label.js +0 -0
  230. /package/{src → lib}/Types/LabelAssociation.js +0 -0
  231. /package/{src → lib}/Types/Message.js +0 -0
  232. /package/{src → lib}/Types/Newsletter.js +0 -0
  233. /package/{src → lib}/Types/Product.js +0 -0
  234. /package/{src → lib}/Types/Signal.js +0 -0
  235. /package/{src → lib}/Types/Socket.js +0 -0
  236. /package/{src → lib}/Types/State.js +0 -0
  237. /package/{src/WABinary/types.js → lib/Types/USync.js} +0 -0
  238. /package/{src → lib}/Types/index.js +0 -0
  239. /package/{src → lib}/Utils/index.js +0 -0
  240. /package/{src → lib}/Utils/logger.js +0 -0
  241. /package/{src → lib}/Utils/lt-hash.js +0 -0
  242. /package/{src → lib}/Utils/noise-handler.js +0 -0
  243. /package/{src → lib}/WABinary/constants.js +0 -0
  244. /package/{src → lib}/WABinary/decode.js +0 -0
  245. /package/{src → lib}/WABinary/generic-utils.js +0 -0
  246. /package/{src → lib}/WABinary/index.js +0 -0
  247. /package/{src → lib}/WABinary/jid-utils.js +0 -0
  248. /package/{src → lib}/WAM/BinaryInfo.js +0 -0
  249. /package/{src → lib}/WAM/constants.js +0 -0
  250. /package/{src → lib}/WAM/encode.js +0 -0
  251. /package/{src → lib}/WAM/index.js +0 -0
@@ -1,123 +1,116 @@
1
-
2
- import { AxiosRequestConfig } from 'axios'
3
- import type { Agent } from 'https'
4
- import type { Logger } from 'pino'
5
- import type { URL } from 'url'
6
- import { proto } from '../../WAProto'
7
- import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth'
8
- import { MediaConnInfo } from './Message'
9
- import { SignalRepository } from './Signal'
10
-
11
- export type WAVersion = [number, number, number]
12
- export type WABrowserDescription = [string, string, string]
13
-
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import type { Agent } from 'https';
3
+ import type { Logger } from 'pino';
4
+ import type { URL } from 'url';
5
+ import { proto } from '../../WAProto';
6
+ import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth';
7
+ import { GroupMetadata } from './GroupMetadata';
8
+ import { MediaConnInfo } from './Message';
9
+ import { SignalRepository } from './Signal';
10
+ export type WAVersion = [number, number, number];
11
+ export type WABrowserDescription = [string, string, string];
14
12
  export type CacheStore = {
15
13
  /** get a cached key and change the stats */
16
- get<T>(key: string): T | undefined
14
+ get<T>(key: string): T | undefined;
17
15
  /** set a key in the cache */
18
- set<T>(key: string, value: T): void
16
+ set<T>(key: string, value: T): void;
19
17
  /** delete a key from the cache */
20
- del(key: string): void
18
+ del(key: string): void;
21
19
  /** flush all data */
22
- flushAll(): void
23
- }
24
-
20
+ flushAll(): void;
21
+ };
25
22
  export type SocketConfig = {
26
23
  /** the WS url to connect to WA */
27
- waWebSocketUrl: string | URL
24
+ waWebSocketUrl: string | URL;
28
25
  /** Fails the connection if the socket times out in this interval */
29
- connectTimeoutMs: number
26
+ connectTimeoutMs: number;
30
27
  /** Default timeout for queries, undefined for no timeout */
31
- defaultQueryTimeoutMs: number | undefined
28
+ defaultQueryTimeoutMs: number | undefined;
32
29
  /** ping-pong interval for WS connection */
33
- keepAliveIntervalMs: number
34
- /** should baileys use the mobile api instead of the multi device api */
35
- mobile?: boolean
30
+ keepAliveIntervalMs: number;
31
+ /** should baileys use the mobile api instead of the multi device api */
32
+ mobile?: boolean;
36
33
  /** proxy agent */
37
- agent?: Agent
34
+ agent?: Agent;
38
35
  /** pino logger */
39
- logger: Logger
36
+ logger: Logger;
40
37
  /** version to connect with */
41
- version: WAVersion
38
+ version: WAVersion;
42
39
  /** override browser config */
43
- browser: WABrowserDescription
40
+ browser: WABrowserDescription;
44
41
  /** agent used for fetch requests -- uploading/downloading media */
45
- fetchAgent?: Agent
42
+ fetchAgent?: Agent;
46
43
  /** should the QR be printed in the terminal */
47
- printQRInTerminal: boolean
44
+ printQRInTerminal: boolean;
48
45
  /** should events be emitted for actions done by this socket connection */
49
- emitOwnEvents: boolean
46
+ emitOwnEvents: boolean;
50
47
  /** custom upload hosts to upload media to */
51
- customUploadHosts: MediaConnInfo['hosts']
48
+ customUploadHosts: MediaConnInfo['hosts'];
52
49
  /** time to wait between sending new retry requests */
53
- retryRequestDelayMs: number
50
+ retryRequestDelayMs: number;
54
51
  /** max retry count */
55
- maxMsgRetryCount: number
52
+ maxMsgRetryCount: number;
56
53
  /** time to wait for the generation of the next QR in ms */
57
- qrTimeout?: number
54
+ qrTimeout?: number;
58
55
  /** provide an auth state object to maintain the auth state */
59
- auth: AuthenticationState
56
+ auth: AuthenticationState;
60
57
  /** manage history processing with this control; by default will sync up everything */
61
- shouldSyncHistoryMessage: (msg: proto.Message.IHistorySyncNotification) => boolean
58
+ shouldSyncHistoryMessage: (msg: proto.Message.IHistorySyncNotification) => boolean;
62
59
  /** transaction capability options for SignalKeyStore */
63
- transactionOpts: TransactionCapabilityOptions
60
+ transactionOpts: TransactionCapabilityOptions;
64
61
  /** marks the client as online whenever the socket successfully connects */
65
- markOnlineOnConnect: boolean
66
-
62
+ markOnlineOnConnect: boolean;
63
+ /** alphanumeric country code (USA -> US) for the number used */
64
+ countryCode: string;
67
65
  /** provide a cache to store media, so does not have to be re-uploaded */
68
- mediaCache?: CacheStore
66
+ mediaCache?: CacheStore;
69
67
  /**
70
68
  * map to store the retry counts for failed messages;
71
69
  * used to determine whether to retry a message or not */
72
- msgRetryCounterCache?: CacheStore
70
+ msgRetryCounterCache?: CacheStore;
73
71
  /** provide a cache to store a user's device list */
74
- userDevicesCache?: CacheStore
72
+ userDevicesCache?: CacheStore;
75
73
  /** cache to store call offers */
76
- callOfferCache?: CacheStore
74
+ callOfferCache?: CacheStore;
75
+ /** cache to track placeholder resends */
76
+ placeholderResendCache?: CacheStore;
77
77
  /** width for link preview images */
78
- linkPreviewImageThumbnailWidth: number
78
+ linkPreviewImageThumbnailWidth: number;
79
79
  /** Should Baileys ask the phone for full history, will be received async */
80
- syncFullHistory: boolean
80
+ syncFullHistory: boolean;
81
81
  /** Should baileys fire init queries automatically, default true */
82
- fireInitQueries: boolean
82
+ fireInitQueries: boolean;
83
83
  /**
84
84
  * generate a high quality link preview,
85
85
  * entails uploading the jpegThumbnail to WA
86
86
  * */
87
- generateHighQualityLinkPreview: boolean
88
-
87
+ generateHighQualityLinkPreview: boolean;
89
88
  /**
90
89
  * Returns if a jid should be ignored,
91
90
  * no event for that jid will be triggered.
92
91
  * Messages from that jid will also not be decrypted
93
92
  * */
94
- shouldIgnoreJid: (jid: string) => boolean | undefined
95
-
93
+ shouldIgnoreJid: (jid: string) => boolean | undefined;
96
94
  /**
97
95
  * Optionally patch the message before sending out
98
96
  * */
99
- patchMessageBeforeSending: (
100
- msg: proto.IMessage,
101
- recipientJids: string[],
102
- ) => Promise<proto.IMessage> | proto.IMessage
103
-
97
+ patchMessageBeforeSending: (msg: proto.IMessage, recipientJids: string[]) => Promise<proto.IMessage> | proto.IMessage;
104
98
  /** verify app state MACs */
105
99
  appStateMacVerification: {
106
- patch: boolean
107
- snapshot: boolean
108
- }
109
-
100
+ patch: boolean;
101
+ snapshot: boolean;
102
+ };
110
103
  /** options for axios */
111
- options: AxiosRequestConfig<{}>
104
+ options: AxiosRequestConfig<{}>;
112
105
  /**
113
106
  * fetch a message from your store
114
107
  * implement this so that messages failed to send
115
108
  * (solves the "this message can take a while" issue) can be retried
116
109
  * */
117
- getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>
118
-
119
- makeSignalRepository: (auth: SignalAuthState) => SignalRepository
120
-
110
+ getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>;
111
+ /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
112
+ cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
113
+ makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
121
114
  /** Socket passthrough */
122
- socket?: any
123
- }
115
+ socket?: any;
116
+ };
@@ -0,0 +1,27 @@
1
+ import { Contact } from './Contact';
2
+ export type WAConnectionState = 'open' | 'connecting' | 'close';
3
+ export type ConnectionState = {
4
+ /** connection is now open, connecting or closed */
5
+ connection: WAConnectionState;
6
+ /** the error that caused the connection to close */
7
+ lastDisconnect?: {
8
+ error: Error | undefined;
9
+ date: Date;
10
+ };
11
+ /** is this a new login */
12
+ isNewLogin?: boolean;
13
+ /** the current QR code */
14
+ qr?: string;
15
+ /** has the device received all pending notifications while it was offline */
16
+ receivedPendingNotifications?: boolean;
17
+ /** legacy connection options */
18
+ legacy?: {
19
+ phoneConnected: boolean;
20
+ user?: Contact;
21
+ };
22
+ /**
23
+ * if the client is shown as an active, online client.
24
+ * If this is false, the primary phone and other devices will receive notifs
25
+ * */
26
+ isOnline?: boolean;
27
+ };
@@ -0,0 +1,25 @@
1
+ import { BinaryNode } from '../WABinary';
2
+ import { USyncUser } from '../WAUSync';
3
+ /**
4
+ * Defines the interface for a USyncQuery protocol
5
+ */
6
+ export interface USyncQueryProtocol {
7
+ /**
8
+ * The name of the protocol
9
+ */
10
+ name: string;
11
+ /**
12
+ * Defines what goes inside the query part of a USyncQuery
13
+ */
14
+ getQueryElement: () => BinaryNode;
15
+ /**
16
+ * Defines what goes inside the user part of a USyncQuery
17
+ */
18
+ getUserElement: (user: USyncUser) => BinaryNode | null;
19
+ /**
20
+ * Parse the result of the query
21
+ * @param data Data from the result
22
+ * @returns Whatever the protocol is supposed to return
23
+ */
24
+ parser: (data: BinaryNode) => unknown;
25
+ }
@@ -0,0 +1,66 @@
1
+ export * from './Auth';
2
+ export * from './GroupMetadata';
3
+ export * from './Chat';
4
+ export * from './Contact';
5
+ export * from './State';
6
+ export * from './Message';
7
+ export * from './Newsletter';
8
+ export * from './Socket';
9
+ export * from './Events';
10
+ export * from './Product';
11
+ export * from './Call';
12
+ export * from './Signal';
13
+ import { AuthenticationState } from './Auth';
14
+ import { SocketConfig } from './Socket';
15
+ export type UserFacingSocketConfig = Partial<SocketConfig> & {
16
+ auth: AuthenticationState;
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
+ iOS(browser: string): [string, string, string];
24
+ linux(browser: string): [string, string, string];
25
+ appropriate(browser: string): [string, string, string];
26
+ };
27
+ export declare enum DisconnectReason {
28
+ connectionClosed = 428,
29
+ connectionLost = 408,
30
+ connectionReplaced = 440,
31
+ timedOut = 408,
32
+ loggedOut = 401,
33
+ badSession = 500,
34
+ restartRequired = 515,
35
+ multideviceMismatch = 411,
36
+ forbidden = 403,
37
+ unavailableService = 503
38
+ }
39
+ export type WAInitResponse = {
40
+ ref: string;
41
+ ttl: number;
42
+ status: 200;
43
+ };
44
+ export type WABusinessHoursConfig = {
45
+ day_of_week: string;
46
+ mode: string;
47
+ open_time?: number;
48
+ close_time?: number;
49
+ };
50
+ export type WABusinessProfile = {
51
+ description: string;
52
+ email: string | undefined;
53
+ business_hours: {
54
+ timezone?: string;
55
+ config?: WABusinessHoursConfig[];
56
+ business_config?: WABusinessHoursConfig[];
57
+ };
58
+ website: string[];
59
+ category?: string;
60
+ wid?: string;
61
+ address?: string;
62
+ };
63
+ export type CurveKeyPair = {
64
+ private: Uint8Array;
65
+ public: Uint8Array;
66
+ };
@@ -0,0 +1,18 @@
1
+ import type { Logger } from 'pino';
2
+ import type { AuthenticationCreds, CacheStore, SignalKeyStore, SignalKeyStoreWithTransaction, TransactionCapabilityOptions } from '../Types';
3
+ /**
4
+ * Adds caching capability to a SignalKeyStore
5
+ * @param store the store to add caching to
6
+ * @param logger to log trace events
7
+ * @param _cache cache store to use
8
+ */
9
+ export declare function makeCacheableSignalKeyStore(store: SignalKeyStore, logger: Logger, _cache?: CacheStore): SignalKeyStore;
10
+ /**
11
+ * Adds DB like transaction capability (https://en.wikipedia.org/wiki/Database_transaction) to the SignalKeyStore,
12
+ * this allows batch read & write operations & improves the performance of the lib
13
+ * @param state the key store to apply this capability to
14
+ * @param logger logger to log events
15
+ * @returns SignalKeyStore with transaction capability
16
+ */
17
+ export declare const addTransactionCapability: (state: SignalKeyStore, logger: Logger, { maxCommitRetries, delayBetweenTriesMs }: TransactionCapabilityOptions) => SignalKeyStoreWithTransaction;
18
+ export declare const initAuthCreds: () => AuthenticationCreds;
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -36,52 +27,46 @@ function makeCacheableSignalKeyStore(store, logger, _cache) {
36
27
  return `${type}.${id}`;
37
28
  }
38
29
  return {
39
- get(type, ids) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- const data = {};
42
- const idsToFetch = [];
43
- for (const id of ids) {
44
- const item = cache.get(getUniqueId(type, id));
45
- if (typeof item !== 'undefined') {
46
- data[id] = item;
47
- }
48
- else {
49
- idsToFetch.push(id);
50
- }
30
+ async get(type, ids) {
31
+ const data = {};
32
+ const idsToFetch = [];
33
+ for (const id of ids) {
34
+ const item = cache.get(getUniqueId(type, id));
35
+ if (typeof item !== 'undefined') {
36
+ data[id] = item;
51
37
  }
52
- if (idsToFetch.length) {
53
- logger.trace({ items: idsToFetch.length }, 'loading from store');
54
- const fetched = yield store.get(type, idsToFetch);
55
- for (const id of idsToFetch) {
56
- const item = fetched[id];
57
- if (item) {
58
- data[id] = item;
59
- cache.set(getUniqueId(type, id), item);
60
- }
38
+ else {
39
+ idsToFetch.push(id);
40
+ }
41
+ }
42
+ if (idsToFetch.length) {
43
+ logger.trace({ items: idsToFetch.length }, 'loading from store');
44
+ const fetched = await store.get(type, idsToFetch);
45
+ for (const id of idsToFetch) {
46
+ const item = fetched[id];
47
+ if (item) {
48
+ data[id] = item;
49
+ cache.set(getUniqueId(type, id), item);
61
50
  }
62
51
  }
63
- return data;
64
- });
52
+ }
53
+ return data;
65
54
  },
66
- set(data) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- let keys = 0;
69
- for (const type in data) {
70
- for (const id in data[type]) {
71
- cache.set(getUniqueId(type, id), data[type][id]);
72
- keys += 1;
73
- }
55
+ async set(data) {
56
+ let keys = 0;
57
+ for (const type in data) {
58
+ for (const id in data[type]) {
59
+ cache.set(getUniqueId(type, id), data[type][id]);
60
+ keys += 1;
74
61
  }
75
- logger.trace({ keys }, 'updated cache');
76
- yield store.set(data);
77
- });
62
+ }
63
+ logger.trace({ keys }, 'updated cache');
64
+ await store.set(data);
78
65
  },
79
- clear() {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- var _a;
82
- cache.flushAll();
83
- yield ((_a = store.clear) === null || _a === void 0 ? void 0 : _a.call(store));
84
- });
66
+ async clear() {
67
+ var _a;
68
+ cache.flushAll();
69
+ await ((_a = store.clear) === null || _a === void 0 ? void 0 : _a.call(store));
85
70
  }
86
71
  };
87
72
  }
@@ -100,7 +85,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
100
85
  let mutations = {};
101
86
  let transactionsInProgress = 0;
102
87
  return {
103
- get: (type, ids) => __awaiter(void 0, void 0, void 0, function* () {
88
+ get: async (type, ids) => {
104
89
  if (isInTransaction()) {
105
90
  const dict = transactionCache[type];
106
91
  const idsRequiringFetch = dict
@@ -109,7 +94,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
109
94
  // only fetch if there are any items to fetch
110
95
  if (idsRequiringFetch.length) {
111
96
  dbQueriesInTransaction += 1;
112
- const result = yield state.get(type, idsRequiringFetch);
97
+ const result = await state.get(type, idsRequiringFetch);
113
98
  transactionCache[type] || (transactionCache[type] = {});
114
99
  Object.assign(transactionCache[type], result);
115
100
  }
@@ -125,7 +110,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
125
110
  else {
126
111
  return state.get(type, ids);
127
112
  }
128
- }),
113
+ },
129
114
  set: data => {
130
115
  if (isInTransaction()) {
131
116
  logger.trace({ types: Object.keys(data) }, 'caching in transaction');
@@ -141,50 +126,48 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
141
126
  }
142
127
  },
143
128
  isInTransaction,
144
- transaction(work) {
145
- return __awaiter(this, void 0, void 0, function* () {
146
- let result;
147
- transactionsInProgress += 1;
129
+ async transaction(work) {
130
+ let result;
131
+ transactionsInProgress += 1;
132
+ if (transactionsInProgress === 1) {
133
+ logger.trace('entering transaction');
134
+ }
135
+ try {
136
+ result = await work();
137
+ // commit if this is the outermost transaction
148
138
  if (transactionsInProgress === 1) {
149
- logger.trace('entering transaction');
150
- }
151
- try {
152
- result = yield work();
153
- // commit if this is the outermost transaction
154
- if (transactionsInProgress === 1) {
155
- if (Object.keys(mutations).length) {
156
- logger.trace('committing transaction');
157
- // retry mechanism to ensure we've some recovery
158
- // in case a transaction fails in the first attempt
159
- let tries = maxCommitRetries;
160
- while (tries) {
161
- tries -= 1;
162
- try {
163
- yield state.set(mutations);
164
- logger.trace({ dbQueriesInTransaction }, 'committed transaction');
165
- break;
166
- }
167
- catch (error) {
168
- logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
169
- yield (0, generics_1.delay)(delayBetweenTriesMs);
170
- }
139
+ if (Object.keys(mutations).length) {
140
+ logger.trace('committing transaction');
141
+ // retry mechanism to ensure we've some recovery
142
+ // in case a transaction fails in the first attempt
143
+ let tries = maxCommitRetries;
144
+ while (tries) {
145
+ tries -= 1;
146
+ try {
147
+ await state.set(mutations);
148
+ logger.trace({ dbQueriesInTransaction }, 'committed transaction');
149
+ break;
150
+ }
151
+ catch (error) {
152
+ logger.warn(`failed to commit ${Object.keys(mutations).length} mutations, tries left=${tries}`);
153
+ await (0, generics_1.delay)(delayBetweenTriesMs);
171
154
  }
172
- }
173
- else {
174
- logger.trace('no mutations in transaction');
175
155
  }
176
156
  }
177
- }
178
- finally {
179
- transactionsInProgress -= 1;
180
- if (transactionsInProgress === 0) {
181
- transactionCache = {};
182
- mutations = {};
183
- dbQueriesInTransaction = 0;
157
+ else {
158
+ logger.trace('no mutations in transaction');
184
159
  }
185
160
  }
186
- return result;
187
- });
161
+ }
162
+ finally {
163
+ transactionsInProgress -= 1;
164
+ if (transactionsInProgress === 0) {
165
+ transactionCache = {};
166
+ mutations = {};
167
+ dbQueriesInTransaction = 0;
168
+ }
169
+ }
170
+ return result;
188
171
  }
189
172
  };
190
173
  function isInTransaction() {
@@ -0,0 +1,16 @@
1
+ import type { BaileysEventEmitter } from '../Types';
2
+ /**
3
+ * Captures events from a baileys event emitter & stores them in a file
4
+ * @param ev The event emitter to read events from
5
+ * @param filename File to save to
6
+ */
7
+ export declare const captureEventStream: (ev: BaileysEventEmitter, filename: string) => void;
8
+ /**
9
+ * Read event file and emit events from there
10
+ * @param filename filename containing event data
11
+ * @param delayIntervalMs delay between each event emit
12
+ */
13
+ export declare const readAndEmitEventStream: (filename: string, delayIntervalMs?: number) => {
14
+ ev: BaileysEventEmitter;
15
+ task: Promise<void>;
16
+ };
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readAndEmitEventStream = exports.captureEventStream = void 0;
7
+ const events_1 = __importDefault(require("events"));
8
+ const fs_1 = require("fs");
9
+ const promises_1 = require("fs/promises");
10
+ const readline_1 = require("readline");
11
+ const generics_1 = require("./generics");
12
+ const make_mutex_1 = require("./make-mutex");
13
+ /**
14
+ * Captures events from a baileys event emitter & stores them in a file
15
+ * @param ev The event emitter to read events from
16
+ * @param filename File to save to
17
+ */
18
+ const captureEventStream = (ev, filename) => {
19
+ const oldEmit = ev.emit;
20
+ // write mutex so data is appended in order
21
+ const writeMutex = (0, make_mutex_1.makeMutex)();
22
+ // monkey patch eventemitter to capture all events
23
+ ev.emit = function (...args) {
24
+ const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n';
25
+ const result = oldEmit.apply(ev, args);
26
+ writeMutex.mutex(async () => {
27
+ await (0, promises_1.writeFile)(filename, content, { flag: 'a' });
28
+ });
29
+ return result;
30
+ };
31
+ };
32
+ exports.captureEventStream = captureEventStream;
33
+ /**
34
+ * Read event file and emit events from there
35
+ * @param filename filename containing event data
36
+ * @param delayIntervalMs delay between each event emit
37
+ */
38
+ const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
39
+ const ev = new events_1.default();
40
+ const fireEvents = async () => {
41
+ // from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
42
+ const fileStream = (0, fs_1.createReadStream)(filename);
43
+ const rl = (0, readline_1.createInterface)({
44
+ input: fileStream,
45
+ crlfDelay: Infinity
46
+ });
47
+ // Note: we use the crlfDelay option to recognize all instances of CR LF
48
+ // ('\r\n') in input.txt as a single line break.
49
+ for await (const line of rl) {
50
+ if (line) {
51
+ const { event, data } = JSON.parse(line);
52
+ ev.emit(event, data);
53
+ delayIntervalMs && await (0, generics_1.delay)(delayIntervalMs);
54
+ }
55
+ }
56
+ fileStream.close();
57
+ };
58
+ return {
59
+ ev,
60
+ task: fireEvents()
61
+ };
62
+ };
63
+ exports.readAndEmitEventStream = readAndEmitEventStream;
@@ -0,0 +1,22 @@
1
+ import { CatalogCollection, OrderDetails, Product, ProductCreate, ProductUpdate, WAMediaUpload, WAMediaUploadFunction } from '../Types';
2
+ import { BinaryNode } from '../WABinary';
3
+ export declare const parseCatalogNode: (node: BinaryNode) => {
4
+ products: Product[];
5
+ nextPageCursor: any;
6
+ };
7
+ export declare const parseCollectionsNode: (node: BinaryNode) => {
8
+ collections: CatalogCollection[];
9
+ };
10
+ export declare const parseOrderDetailsNode: (node: BinaryNode) => OrderDetails;
11
+ export declare const toProductNode: (productId: string | undefined, product: ProductCreate | ProductUpdate) => BinaryNode;
12
+ export declare const parseProductNode: (productNode: BinaryNode) => Product;
13
+ /**
14
+ * Uploads images not already uploaded to WA's servers
15
+ */
16
+ export declare function uploadingNecessaryImagesOfProduct<T extends ProductUpdate | ProductCreate>(product: T, waUploadToServer: WAMediaUploadFunction, timeoutMs?: number): Promise<T>;
17
+ /**
18
+ * Uploads images not already uploaded to WA's servers
19
+ */
20
+ export declare const uploadingNecessaryImages: (images: WAMediaUpload[], waUploadToServer: WAMediaUploadFunction, timeoutMs?: number) => Promise<{
21
+ url: string;
22
+ }[]>;