@queenanya/baileys 7.4.13 → 7.5.1

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 (110) hide show
  1. package/README.md +26 -26
  2. package/lib/Defaults/baileys-version.json +1 -1
  3. package/lib/Defaults/index.d.ts +1 -231
  4. package/lib/Defaults/index.js +11 -23
  5. package/lib/Socket/Client/index.d.ts +2 -3
  6. package/lib/Socket/Client/index.js +2 -3
  7. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
  8. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
  9. package/lib/Socket/business.d.ts +31 -28
  10. package/lib/Socket/chats.d.ts +17 -9
  11. package/lib/Socket/chats.js +115 -116
  12. package/lib/Socket/{registration.d.ts → communities.d.ts} +94 -145
  13. package/lib/Socket/communities.js +354 -0
  14. package/lib/Socket/groups.d.ts +23 -10
  15. package/lib/Socket/groups.js +12 -1
  16. package/lib/Socket/index.d.ts +69 -38
  17. package/lib/Socket/index.js +2 -2
  18. package/lib/Socket/messages-recv.d.ts +30 -28
  19. package/lib/Socket/messages-recv.js +291 -180
  20. package/lib/Socket/messages-send.d.ts +25 -19
  21. package/lib/Socket/messages-send.js +110 -76
  22. package/lib/Socket/newsletter.d.ts +19 -13
  23. package/lib/Socket/newsletter.js +67 -54
  24. package/lib/Socket/socket.d.ts +3 -1
  25. package/lib/Socket/socket.js +15 -17
  26. package/lib/Socket/usync.d.ts +38 -0
  27. package/lib/Socket/usync.js +70 -0
  28. package/lib/Store/make-cache-manager-store.d.ts +2 -1
  29. package/lib/Store/make-in-memory-store.js +13 -11
  30. package/lib/Store/make-ordered-dictionary.js +2 -2
  31. package/lib/Types/Auth.d.ts +1 -6
  32. package/lib/Types/Call.d.ts +1 -1
  33. package/lib/Types/Chat.d.ts +15 -7
  34. package/lib/Types/Contact.d.ts +6 -1
  35. package/lib/Types/Events.d.ts +44 -2
  36. package/lib/Types/GroupMetadata.d.ts +3 -1
  37. package/lib/Types/Label.d.ts +11 -0
  38. package/lib/Types/Message.d.ts +37 -30
  39. package/lib/Types/Newsletter.d.ts +0 -13
  40. package/lib/Types/Newsletter.js +1 -15
  41. package/lib/Types/Socket.d.ts +10 -3
  42. package/lib/Types/USync.d.ts +25 -0
  43. package/lib/Types/USync.js +2 -0
  44. package/lib/Types/index.d.ts +8 -0
  45. package/lib/Utils/auth-utils.js +1 -7
  46. package/lib/Utils/chat-utils.d.ts +5 -4
  47. package/lib/Utils/chat-utils.js +52 -20
  48. package/lib/Utils/crypto.d.ts +2 -1
  49. package/lib/Utils/crypto.js +4 -2
  50. package/lib/Utils/decode-wa-message.d.ts +1 -0
  51. package/lib/Utils/decode-wa-message.js +34 -14
  52. package/lib/Utils/event-buffer.js +14 -8
  53. package/lib/Utils/generics.d.ts +37 -13
  54. package/lib/Utils/generics.js +103 -18
  55. package/lib/Utils/history.d.ts +6 -2
  56. package/lib/Utils/history.js +3 -0
  57. package/lib/Utils/index.d.ts +1 -0
  58. package/lib/Utils/index.js +1 -0
  59. package/lib/Utils/link-preview.js +24 -1
  60. package/lib/Utils/logger.d.ts +1 -3
  61. package/lib/Utils/make-mutex.js +1 -0
  62. package/lib/Utils/messages-media.d.ts +3 -2
  63. package/lib/Utils/messages-media.js +17 -32
  64. package/lib/Utils/messages.d.ts +1 -0
  65. package/lib/Utils/messages.js +67 -72
  66. package/lib/Utils/noise-handler.d.ts +3 -3
  67. package/lib/Utils/noise-handler.js +7 -12
  68. package/lib/Utils/process-message.d.ts +3 -2
  69. package/lib/Utils/process-message.js +55 -21
  70. package/lib/Utils/signal.js +23 -16
  71. package/lib/Utils/use-multi-file-auth-state.js +17 -3
  72. package/lib/Utils/validate-connection.d.ts +0 -1
  73. package/lib/Utils/validate-connection.js +10 -44
  74. package/lib/WABinary/constants.js +5 -5
  75. package/lib/WABinary/decode.d.ts +3 -2
  76. package/lib/WABinary/decode.js +6 -4
  77. package/lib/WABinary/encode.d.ts +1 -2
  78. package/lib/WABinary/encode.js +8 -6
  79. package/lib/WABinary/generic-utils.d.ts +1 -0
  80. package/lib/WABinary/jid-utils.d.ts +3 -3
  81. package/lib/WABinary/jid-utils.js +5 -5
  82. package/lib/WAM/BinaryInfo.d.ts +3 -2
  83. package/lib/WAM/constants.d.ts +3 -2
  84. package/lib/WAM/encode.d.ts +1 -0
  85. package/lib/WAM/encode.js +2 -2
  86. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  87. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  88. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  89. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  90. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  91. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  92. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  93. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  94. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  95. package/lib/WAUSync/Protocols/index.js +20 -0
  96. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  97. package/lib/WAUSync/USyncQuery.js +79 -0
  98. package/lib/WAUSync/USyncUser.d.ts +10 -0
  99. package/lib/WAUSync/USyncUser.js +22 -0
  100. package/lib/WAUSync/index.d.ts +3 -0
  101. package/lib/WAUSync/index.js +19 -0
  102. package/lib/index.d.ts +1 -0
  103. package/lib/index.js +1 -0
  104. package/package.json +37 -35
  105. package/lib/Defaults/phonenumber-mcc.json +0 -223
  106. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  107. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  108. package/lib/Socket/registration.js +0 -166
  109. /package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +0 -0
  110. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -4,11 +4,12 @@ import { AuthenticationCreds } from './Auth';
4
4
  import { WACallEvent } from './Call';
5
5
  import { Chat, ChatUpdate, PresenceData } from './Chat';
6
6
  import { Contact } from './Contact';
7
- import { GroupMetadata, ParticipantAction } from './GroupMetadata';
7
+ import { GroupMetadata, ParticipantAction, RequestJoinAction, RequestJoinMethod } from './GroupMetadata';
8
8
  import { Label } from './Label';
9
9
  import { LabelAssociation } from './LabelAssociation';
10
10
  import { MessageUpsertType, MessageUserReceiptUpdate, WAMessage, WAMessageKey, WAMessageUpdate } from './Message';
11
11
  import { ConnectionState } from './State';
12
+ import { NewsletterSettingsUpdate, SubscriberAction, NewsletterViewRole } from './Newsletter';
12
13
  export type BaileysEventMap = {
13
14
  /** connection state has been updated -- WS closed, opened, connecting etc. */
14
15
  'connection.update': Partial<ConnectionState>;
@@ -19,7 +20,10 @@ export type BaileysEventMap = {
19
20
  chats: Chat[];
20
21
  contacts: Contact[];
21
22
  messages: WAMessage[];
22
- isLatest: boolean;
23
+ isLatest?: boolean;
24
+ progress?: number | null;
25
+ syncType?: proto.HistorySync.HistorySyncType;
26
+ peerDataRequestSessionId?: string | null;
23
27
  };
24
28
  /** upsert chats */
25
29
  'chats.upsert': Chat[];
@@ -58,10 +62,12 @@ export type BaileysEventMap = {
58
62
  /**
59
63
  * add/update the given messages. If they were received while the connection was online,
60
64
  * the update will have type: "notify"
65
+ * if requestId is provided, then the messages was received from the phone due to it being unavailable
61
66
  * */
62
67
  'messages.upsert': {
63
68
  messages: WAMessage[];
64
69
  type: MessageUpsertType;
70
+ requestId?: string;
65
71
  };
66
72
  /** message was reacted to. If reaction was removed -- then "reaction.text" will be falsey */
67
73
  'messages.reaction': {
@@ -78,6 +84,39 @@ export type BaileysEventMap = {
78
84
  participants: string[];
79
85
  action: ParticipantAction;
80
86
  };
87
+ 'group.join-request': {
88
+ id: string;
89
+ author: string;
90
+ participant: string;
91
+ action: RequestJoinAction;
92
+ method: RequestJoinMethod;
93
+ };
94
+ 'newsletter.reaction': {
95
+ id: string;
96
+ server_id: string;
97
+ reaction: {
98
+ code?: string;
99
+ count?: number;
100
+ removed?: boolean;
101
+ };
102
+ };
103
+ 'newsletter.view': {
104
+ id: string;
105
+ server_id: string;
106
+ count: number;
107
+ };
108
+ /**don't handles subscribe/unsubscribe actions */
109
+ 'newsletter-participants.update': {
110
+ id: string;
111
+ author: string;
112
+ user: string;
113
+ new_role: NewsletterViewRole;
114
+ action: SubscriberAction;
115
+ };
116
+ 'newsletter-settings.update': {
117
+ id: string;
118
+ update: NewsletterSettingsUpdate;
119
+ };
81
120
  'blocklist.set': {
82
121
  blocklist: string[];
83
122
  };
@@ -106,6 +145,9 @@ export type BufferedEventData = {
106
145
  };
107
146
  empty: boolean;
108
147
  isLatest: boolean;
148
+ progress?: number | null;
149
+ syncType?: proto.HistorySync.HistorySyncType;
150
+ peerDataRequestSessionId?: string;
109
151
  };
110
152
  chatUpserts: {
111
153
  [jid: string]: Chat;
@@ -4,7 +4,9 @@ export type GroupParticipant = (Contact & {
4
4
  isSuperAdmin?: boolean;
5
5
  admin?: 'admin' | 'superadmin' | null;
6
6
  });
7
- export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote';
7
+ export type ParticipantAction = 'add' | 'remove' | 'promote' | 'demote' | 'modify';
8
+ export type RequestJoinAction = 'created' | 'revoked' | 'rejected';
9
+ export type RequestJoinMethod = 'invite_link' | 'linked_group_join' | 'non_admin_add' | undefined;
8
10
  export interface GroupMetadata {
9
11
  id: string;
10
12
  owner: string | undefined;
@@ -10,6 +10,17 @@ export interface Label {
10
10
  /** WhatsApp has 5 predefined labels (New customer, New order & etc) */
11
11
  predefinedId?: string;
12
12
  }
13
+ export interface LabelActionBody {
14
+ id: string;
15
+ /** Label name */
16
+ name?: string;
17
+ /** Label color ID */
18
+ color?: number;
19
+ /** Is label has been deleted */
20
+ deleted?: boolean;
21
+ /** WhatsApp has 5 predefined labels (New customer, New order & etc) */
22
+ predefinedId?: number;
23
+ }
13
24
  /** WhatsApp has 20 predefined colors */
14
25
  export declare enum LabelColor {
15
26
  Color1 = 0,
@@ -1,13 +1,14 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  /// <reference types="node" />
4
+ /// <reference types="node" />
4
5
  import { AxiosRequestConfig } from 'axios';
5
6
  import type { Logger } from 'pino';
6
7
  import type { Readable } from 'stream';
7
8
  import type { URL } from 'url';
8
- import { BinaryNode } from '../WABinary';
9
9
  import { proto } from '../../WAProto';
10
10
  import { MEDIA_HKDF_KEY_MAPPING } from '../Defaults';
11
+ import { BinaryNode } from '../WABinary';
11
12
  import type { GroupMetadata } from './GroupMetadata';
12
13
  import { CacheStore } from './Socket';
13
14
  export { proto as WAProto };
@@ -15,18 +16,22 @@ export type WAMessage = proto.IWebMessageInfo;
15
16
  export type WAMessageContent = proto.IMessage;
16
17
  export type WAContactMessage = proto.Message.IContactMessage;
17
18
  export type WAContactsArrayMessage = proto.Message.IContactsArrayMessage;
18
- export type WAMessageKey = proto.IMessageKey;
19
+ export type WAMessageKey = proto.IMessageKey & {
20
+ server_id?: string;
21
+ };
19
22
  export type WATextMessage = proto.Message.IExtendedTextMessage;
20
23
  export type WAContextInfo = proto.IContextInfo;
21
24
  export type WALocationMessage = proto.Message.ILocationMessage;
22
25
  export type WAGenericMediaMessage = proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
23
26
  export import WAMessageStubType = proto.WebMessageInfo.StubType;
24
27
  export import WAMessageStatus = proto.WebMessageInfo.Status;
25
- export type WAMediaUpload = Buffer | {
28
+ export type WAMediaPayloadURL = {
26
29
  url: URL | string;
27
- } | {
30
+ };
31
+ export type WAMediaPayloadStream = {
28
32
  stream: Readable;
29
33
  };
34
+ export type WAMediaUpload = Buffer | WAMediaPayloadStream | WAMediaPayloadURL;
30
35
  /** Set of message types that are supported by the library */
31
36
  export type MessageType = keyof proto.Message;
32
37
  export type DownloadableMessage = {
@@ -64,26 +69,9 @@ type Contextable = {
64
69
  type ViewOnce = {
65
70
  viewOnce?: boolean;
66
71
  };
67
- type Buttonable = {
68
- /** add buttons to the message */
69
- buttons?: proto.Message.ButtonsMessage.IButton[];
70
- };
71
- type Templatable = {
72
- /** add buttons to the message (conflicts with normal buttons)*/
73
- templateButtons?: proto.IHydratedTemplateButton[];
74
- footer?: string;
75
- };
76
72
  type Editable = {
77
73
  edit?: WAMessageKey;
78
74
  };
79
- type Listable = {
80
- /** Sections of the List */
81
- sections?: proto.Message.ListMessage.ISection[];
82
- /** Title of a List Message only */
83
- title?: string;
84
- /** Text of the bnutton on the list (required) */
85
- buttonText?: string;
86
- };
87
75
  type WithDimensions = {
88
76
  width?: number;
89
77
  height?: number;
@@ -94,6 +82,7 @@ export type PollMessageOptions = {
94
82
  values: string[];
95
83
  /** 32 byte message secret to encrypt poll selections */
96
84
  messageSecret?: Uint8Array;
85
+ toAnnouncementGroup?: boolean;
97
86
  };
98
87
  type SharePhoneNumber = {
99
88
  sharePhoneNumber: boolean;
@@ -106,14 +95,14 @@ export type AnyMediaMessageContent = (({
106
95
  image: WAMediaUpload;
107
96
  caption?: string;
108
97
  jpegThumbnail?: string;
109
- } & Mentionable & Contextable & Buttonable & Templatable & WithDimensions) | ({
98
+ } & Mentionable & Contextable & WithDimensions) | ({
110
99
  video: WAMediaUpload;
111
100
  caption?: string;
112
101
  gifPlayback?: boolean;
113
102
  jpegThumbnail?: string;
114
103
  /** if set to true, will send as a `video note` */
115
104
  ptv?: boolean;
116
- } & Mentionable & Contextable & Buttonable & Templatable & WithDimensions) | {
105
+ } & Mentionable & Contextable & WithDimensions) | {
117
106
  audio: WAMediaUpload;
118
107
  /** if set to true, will send as a `voice note` */
119
108
  ptt?: boolean;
@@ -127,7 +116,7 @@ export type AnyMediaMessageContent = (({
127
116
  mimetype: string;
128
117
  fileName?: string;
129
118
  caption?: string;
130
- } & Contextable & Buttonable & Templatable)) & {
119
+ } & Contextable)) & {
131
120
  mimetype?: string;
132
121
  } & Editable;
133
122
  export type ButtonReplyInfo = {
@@ -135,15 +124,22 @@ export type ButtonReplyInfo = {
135
124
  id: string;
136
125
  index: number;
137
126
  };
127
+ export type GroupInviteInfo = {
128
+ inviteCode: string;
129
+ inviteExpiration: number;
130
+ text: string;
131
+ jid: string;
132
+ subject: string;
133
+ };
138
134
  export type WASendableProduct = Omit<proto.Message.ProductMessage.IProductSnapshot, 'productImage'> & {
139
135
  productImage: WAMediaUpload;
140
136
  };
141
137
  export type AnyRegularMessageContent = (({
142
138
  text: string;
143
139
  linkPreview?: WAUrlInfo | null;
144
- } & Mentionable & Contextable & Buttonable & Templatable & Listable & Editable) | AnyMediaMessageContent | ({
140
+ } & Mentionable & Contextable & Editable) | AnyMediaMessageContent | ({
145
141
  poll: PollMessageOptions;
146
- } & Mentionable & Contextable & Buttonable & Templatable & Editable) | {
142
+ } & Mentionable & Contextable & Editable) | {
147
143
  contacts: {
148
144
  displayName?: string;
149
145
  contacts: proto.Message.IContactMessage[];
@@ -155,8 +151,19 @@ export type AnyRegularMessageContent = (({
155
151
  } | {
156
152
  buttonReply: ButtonReplyInfo;
157
153
  type: 'template' | 'plain';
154
+ } | {
155
+ groupInvite: GroupInviteInfo;
158
156
  } | {
159
157
  listReply: Omit<proto.Message.IListResponseMessage, 'contextInfo'>;
158
+ } | {
159
+ pin: WAMessageKey;
160
+ type: proto.PinInChat.Type;
161
+ /**
162
+ * 24 hours, 7 days, 30 days
163
+ */
164
+ time?: 86400 | 604800 | 2592000;
165
+ } | {
166
+ unpin: WAMessageKey;
160
167
  } | {
161
168
  product: WASendableProduct;
162
169
  businessOwnerJid?: string;
@@ -176,8 +183,8 @@ export type GroupMetadataParticipants = Pick<GroupMetadata, 'participants'>;
176
183
  type MinimalRelayOptions = {
177
184
  /** override the message ID with a custom provided string */
178
185
  messageId?: string;
179
- /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
180
- cachedGroupMetadata?: (jid: string) => Promise<GroupMetadataParticipants | undefined>;
186
+ /** should we use group metadata cache, or fetch afresh from the server; default assumed to be "true" */
187
+ useCachedGroupMetadata?: boolean;
181
188
  };
182
189
  export type MessageRelayOptions = MinimalRelayOptions & {
183
190
  /** only send to a specific participant; used when a message decryption fails for a single user */
@@ -200,7 +207,6 @@ export type MiscMessageGenerationOptions = MinimalRelayOptions & {
200
207
  timestamp?: Date;
201
208
  /** the message you want to quote */
202
209
  quoted?: WAMessage;
203
- additionalNodes?: BinaryNode[];
204
210
  /** disappearing messages settings */
205
211
  ephemeralExpiration?: number | string;
206
212
  /** timeout for media upload to WA server */
@@ -237,12 +243,13 @@ export type MediaGenerationOptions = {
237
243
  mediaUploadTimeoutMs?: number;
238
244
  options?: AxiosRequestConfig;
239
245
  backgroundColor?: string;
240
- font?: number;
241
246
  /** The message is for newsletter? */
242
247
  newsletter?: boolean;
248
+ font?: number;
243
249
  };
244
250
  export type MessageContentGenerationOptions = MediaGenerationOptions & {
245
251
  getUrlInfo?: (text: string) => Promise<WAUrlInfo | undefined>;
252
+ getProfilePicUrl?: (jid: string, type: 'image' | 'preview') => Promise<string | undefined>;
246
253
  };
247
254
  export type MessageGenerationOptions = MessageContentGenerationOptions & MessageGenerationOptionsFromContent;
248
255
  /**
@@ -77,16 +77,3 @@ export declare enum XWAPaths {
77
77
  NEWSLETTER = "xwa2_newsletter",
78
78
  METADATA_UPDATE = "xwa2_notify_newsletter_on_metadata_update"
79
79
  }
80
- export declare enum QueryIds {
81
- JOB_MUTATION = "7150902998257522",
82
- METADATA = "6620195908089573",
83
- UNFOLLOW = "7238632346214362",
84
- FOLLOW = "7871414976211147",
85
- UNMUTE = "7337137176362961",
86
- MUTE = "25151904754424642",
87
- CREATE = "6996806640408138",
88
- ADMIN_COUNT = "7130823597031706",
89
- CHANGE_OWNER = "7341777602580933",
90
- DELETE = "8316537688363079",
91
- DEMOTE = "6551828931592903"
92
- }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.QueryIds = exports.XWAPaths = exports.MexOperations = void 0;
3
+ exports.XWAPaths = exports.MexOperations = void 0;
4
4
  var MexOperations;
5
5
  (function (MexOperations) {
6
6
  MexOperations["PROMOTE"] = "NotificationNewsletterAdminPromote";
@@ -16,17 +16,3 @@ var XWAPaths;
16
16
  XWAPaths["NEWSLETTER"] = "xwa2_newsletter";
17
17
  XWAPaths["METADATA_UPDATE"] = "xwa2_notify_newsletter_on_metadata_update";
18
18
  })(XWAPaths = exports.XWAPaths || (exports.XWAPaths = {}));
19
- var QueryIds;
20
- (function (QueryIds) {
21
- QueryIds["JOB_MUTATION"] = "7150902998257522";
22
- QueryIds["METADATA"] = "6620195908089573";
23
- QueryIds["UNFOLLOW"] = "7238632346214362";
24
- QueryIds["FOLLOW"] = "7871414976211147";
25
- QueryIds["UNMUTE"] = "7337137176362961";
26
- QueryIds["MUTE"] = "25151904754424642";
27
- QueryIds["CREATE"] = "6996806640408138";
28
- QueryIds["ADMIN_COUNT"] = "7130823597031706";
29
- QueryIds["CHANGE_OWNER"] = "7341777602580933";
30
- QueryIds["DELETE"] = "8316537688363079";
31
- QueryIds["DEMOTE"] = "6551828931592903";
32
- })(QueryIds = exports.QueryIds || (exports.QueryIds = {}));
@@ -6,6 +6,7 @@ import type { Logger } from 'pino';
6
6
  import type { URL } from 'url';
7
7
  import { proto } from '../../WAProto';
8
8
  import { AuthenticationState, SignalAuthState, TransactionCapabilityOptions } from './Auth';
9
+ import { GroupMetadata } from './GroupMetadata';
9
10
  import { MediaConnInfo } from './Message';
10
11
  import { SignalRepository } from './Signal';
11
12
  export type WAVersion = [number, number, number];
@@ -29,7 +30,9 @@ export type SocketConfig = {
29
30
  defaultQueryTimeoutMs: number | undefined;
30
31
  /** ping-pong interval for WS connection */
31
32
  keepAliveIntervalMs: number;
32
- /** should baileys use the mobile api instead of the multi device api */
33
+ /** should baileys use the mobile api instead of the multi device api
34
+ * @deprecated This feature has been removed
35
+ */
33
36
  mobile?: boolean;
34
37
  /** proxy agent */
35
38
  agent?: Agent;
@@ -71,10 +74,14 @@ export type SocketConfig = {
71
74
  userDevicesCache?: CacheStore;
72
75
  /** cache to store call offers */
73
76
  callOfferCache?: CacheStore;
77
+ /** cache to track placeholder resends */
78
+ placeholderResendCache?: CacheStore;
74
79
  /** width for link preview images */
75
80
  linkPreviewImageThumbnailWidth: number;
76
81
  /** Should Baileys ask the phone for full history, will be received async */
77
82
  syncFullHistory: boolean;
83
+ /** Ignore Message when offline, default is false */
84
+ ignoreMsgLoading: boolean;
78
85
  /** Should baileys fire init queries automatically, default true */
79
86
  fireInitQueries: boolean;
80
87
  /**
@@ -105,7 +112,7 @@ export type SocketConfig = {
105
112
  * (solves the "this message can take a while" issue) can be retried
106
113
  * */
107
114
  getMessage: (key: proto.IMessageKey) => Promise<proto.IMessage | undefined>;
115
+ /** cached group metadata, use to prevent redundant requests to WA & speed up msg sending */
116
+ cachedGroupMetadata: (jid: string) => Promise<GroupMetadata | undefined>;
108
117
  makeSignalRepository: (auth: SignalAuthState) => SignalRepository;
109
- /** Socket passthrough */
110
- socket?: any;
111
118
  };
@@ -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,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -15,6 +15,14 @@ import { SocketConfig } from './Socket';
15
15
  export type UserFacingSocketConfig = Partial<SocketConfig> & {
16
16
  auth: AuthenticationState;
17
17
  };
18
+ /** Other Browser Support for Paircode */
19
+ export type BrowsersMap = {
20
+ ubuntu(browser: string): [string, string, string];
21
+ macOS(browser: string): [string, string, string];
22
+ baileys(browser: string): [string, string, string];
23
+ windows(browser: string): [string, string, string];
24
+ appropriate(browser: string): [string, string, string];
25
+ };
18
26
  export declare enum DisconnectReason {
19
27
  connectionClosed = 428,
20
28
  connectionLost = 408,
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.initAuthCreds = exports.addTransactionCapability = exports.makeCacheableSignalKeyStore = void 0;
7
7
  const crypto_1 = require("crypto");
8
8
  const node_cache_1 = __importDefault(require("node-cache"));
9
- const uuid_1 = require("uuid");
10
9
  const Defaults_1 = require("../Defaults");
11
10
  const crypto_2 = require("./crypto");
12
11
  const generics_1 = require("./generics");
@@ -143,6 +142,7 @@ const addTransactionCapability = (state, logger, { maxCommitRetries, delayBetwee
143
142
  let tries = maxCommitRetries;
144
143
  while (tries) {
145
144
  tries -= 1;
145
+ //eslint-disable-next-line max-depth
146
146
  try {
147
147
  await state.set(mutations);
148
148
  logger.trace({ dbQueriesInTransaction }, 'committed transaction');
@@ -191,13 +191,7 @@ const initAuthCreds = () => {
191
191
  accountSettings: {
192
192
  unarchiveChats: false
193
193
  },
194
- // mobile creds
195
- deviceId: Buffer.from((0, uuid_1.v4)().replace(/-/g, ''), 'hex').toString('base64url'),
196
- phoneId: (0, uuid_1.v4)(),
197
- identityId: (0, crypto_1.randomBytes)(20),
198
194
  registered: false,
199
- backupToken: (0, crypto_1.randomBytes)(20),
200
- registration: {},
201
195
  pairingCode: undefined,
202
196
  lastPropHash: undefined,
203
197
  routingInfo: undefined,
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { AxiosRequestConfig } from 'axios';
3
4
  import type { Logger } from 'pino';
4
5
  import { proto } from '../../WAProto';
@@ -29,7 +30,7 @@ export declare const decodeSyncdPatch: (msg: proto.ISyncdPatch, name: WAPatchNam
29
30
  };
30
31
  };
31
32
  }>;
32
- export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<any>) => Promise<{
33
+ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosRequestConfig<{}>) => Promise<{
33
34
  critical_block: {
34
35
  patches: proto.ISyncdPatch[];
35
36
  hasMorePatches: boolean;
@@ -56,13 +57,13 @@ export declare const extractSyncdPatches: (result: BinaryNode, options: AxiosReq
56
57
  snapshot?: proto.ISyncdSnapshot | undefined;
57
58
  };
58
59
  }>;
59
- export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<Buffer>;
60
- export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<any>) => Promise<proto.SyncdMutations>;
60
+ export declare const downloadExternalBlob: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<Buffer>;
61
+ export declare const downloadExternalPatch: (blob: proto.IExternalBlobReference, options: AxiosRequestConfig<{}>) => Promise<proto.SyncdMutations>;
61
62
  export declare const decodeSyncdSnapshot: (name: WAPatchName, snapshot: proto.ISyncdSnapshot, getAppStateSyncKey: FetchAppStateSyncKey, minimumVersionNumber: number | undefined, validateMacs?: boolean) => Promise<{
62
63
  state: LTHashState;
63
64
  mutationMap: ChatMutationMap;
64
65
  }>;
65
- export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<any>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
66
+ export declare const decodePatches: (name: WAPatchName, syncds: proto.ISyncdPatch[], initial: LTHashState, getAppStateSyncKey: FetchAppStateSyncKey, options: AxiosRequestConfig<{}>, minimumVersionNumber?: number, logger?: Logger, validateMacs?: boolean) => Promise<{
66
67
  state: LTHashState;
67
68
  mutationMap: ChatMutationMap;
68
69
  }>;
@@ -305,8 +305,7 @@ const decodePatches = async (name, syncds, initial, getAppStateSyncKey, options,
305
305
  indexValueMap: { ...initial.indexValueMap }
306
306
  };
307
307
  const mutationMap = {};
308
- for (let i = 0; i < syncds.length; i++) {
309
- const syncd = syncds[i];
308
+ for (const syncd of syncds) {
310
309
  const { version, keyId, snapshotMac } = syncd;
311
310
  if (syncd.externalMutations) {
312
311
  logger === null || logger === void 0 ? void 0 : logger.trace({ name, version }, 'downloading external patch');
@@ -418,25 +417,31 @@ const chatModificationToAppPatch = (mod, jid) => {
418
417
  operation: OP.SET
419
418
  };
420
419
  }
420
+ else if ('deleteForMe' in mod) {
421
+ const { timestamp, key, deleteMedia } = mod.deleteForMe;
422
+ patch = {
423
+ syncAction: {
424
+ deleteMessageForMeAction: {
425
+ deleteMedia,
426
+ messageTimestamp: timestamp
427
+ }
428
+ },
429
+ index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
430
+ type: 'regular_high',
431
+ apiVersion: 3,
432
+ operation: OP.SET
433
+ };
434
+ }
421
435
  else if ('clear' in mod) {
422
- if (mod.clear === 'all') {
423
- throw new boom_1.Boom('not supported');
424
- }
425
- else {
426
- const key = mod.clear.messages[0];
427
- patch = {
428
- syncAction: {
429
- deleteMessageForMeAction: {
430
- deleteMedia: false,
431
- messageTimestamp: key.timestamp
432
- }
433
- },
434
- index: ['deleteMessageForMe', jid, key.id, key.fromMe ? '1' : '0', '0'],
435
- type: 'regular_high',
436
- apiVersion: 3,
437
- operation: OP.SET
438
- };
439
- }
436
+ patch = {
437
+ syncAction: {
438
+ clearChatAction: {} // add message range later
439
+ },
440
+ index: ['clearChat', jid, '1' /*the option here is 0 when keep starred messages is enabled*/, '0'],
441
+ type: 'regular_high',
442
+ apiVersion: 6,
443
+ operation: OP.SET
444
+ };
440
445
  }
441
446
  else if ('pin' in mod) {
442
447
  patch = {
@@ -451,6 +456,17 @@ const chatModificationToAppPatch = (mod, jid) => {
451
456
  operation: OP.SET
452
457
  };
453
458
  }
459
+ else if ('contact' in mod) {
460
+ patch = {
461
+ syncAction: {
462
+ contactAction: mod.contact || {}
463
+ },
464
+ index: ['contact', jid],
465
+ type: 'critical_unblock_low',
466
+ apiVersion: 2,
467
+ operation: mod.contact ? OP.SET : OP.REMOVE
468
+ };
469
+ }
454
470
  else if ('star' in mod) {
455
471
  const key = mod.star.messages[0];
456
472
  patch = {
@@ -491,6 +507,22 @@ const chatModificationToAppPatch = (mod, jid) => {
491
507
  operation: OP.SET,
492
508
  };
493
509
  }
510
+ else if ('addLabel' in mod) {
511
+ patch = {
512
+ syncAction: {
513
+ labelEditAction: {
514
+ name: mod.addLabel.name,
515
+ color: mod.addLabel.color,
516
+ predefinedId: mod.addLabel.predefinedId,
517
+ deleted: mod.addLabel.deleted
518
+ }
519
+ },
520
+ index: ['label_edit', mod.addLabel.id],
521
+ type: 'regular',
522
+ apiVersion: 3,
523
+ operation: OP.SET,
524
+ };
525
+ }
494
526
  else if ('addChatLabel' in mod) {
495
527
  patch = {
496
528
  syncAction: {
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
2
3
  import { KeyPair } from '../Types';
3
4
  /** prefix version byte to the pub keys, required for some curve crypto functions */
4
5
  export declare const generateSignalPubKey: (pubKey: Uint8Array | Buffer) => Uint8Array | Buffer;
@@ -38,4 +39,4 @@ export declare function hkdf(buffer: Uint8Array | Buffer, expandedLength: number
38
39
  salt?: Buffer;
39
40
  info?: string;
40
41
  }): Buffer;
41
- export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Buffer;
42
+ export declare function derivePairingCodeKey(pairingCode: string, salt: Buffer): Promise<Buffer>;
@@ -30,7 +30,9 @@ exports.derivePairingCodeKey = exports.hkdf = exports.md5 = exports.sha256 = exp
30
30
  const crypto_1 = require("crypto");
31
31
  const futoin_hkdf_1 = __importDefault(require("futoin-hkdf"));
32
32
  const libsignal = __importStar(require("libsignal"));
33
+ const util_1 = require("util");
33
34
  const Defaults_1 = require("../Defaults");
35
+ const pbkdf2Promise = (0, util_1.promisify)(crypto_1.pbkdf2);
34
36
  /** prefix version byte to the pub keys, required for some curve crypto functions */
35
37
  const generateSignalPubKey = (pubKey) => (pubKey.length === 33
36
38
  ? pubKey
@@ -145,7 +147,7 @@ function hkdf(buffer, expandedLength, info) {
145
147
  return (0, futoin_hkdf_1.default)(!Buffer.isBuffer(buffer) ? Buffer.from(buffer) : buffer, expandedLength, info);
146
148
  }
147
149
  exports.hkdf = hkdf;
148
- function derivePairingCodeKey(pairingCode, salt) {
149
- return (0, crypto_1.pbkdf2Sync)(pairingCode, salt, 2 << 16, 32, 'sha256');
150
+ async function derivePairingCodeKey(pairingCode, salt) {
151
+ return await pbkdf2Promise(pairingCode, salt, 2 << 16, 32, 'sha256');
150
152
  }
151
153
  exports.derivePairingCodeKey = derivePairingCodeKey;
@@ -2,6 +2,7 @@ import { Logger } from 'pino';
2
2
  import { proto } from '../../WAProto';
3
3
  import { SignalRepository } from '../Types';
4
4
  import { BinaryNode } from '../WABinary';
5
+ export declare const NO_MESSAGE_FOUND_ERROR_TEXT = "Message absent from node";
5
6
  /**
6
7
  * Decode the received node as a message.
7
8
  * @note this will only parse the message, not decrypt it