@jkt48connect-corp/baileys 7.3.1 → 7.3.2

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 (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1119 -1407
  3. package/lib/Defaults/baileys-version.json +1 -1
  4. package/lib/Defaults/index.d.ts +7 -9
  5. package/lib/Defaults/index.js +4 -6
  6. package/lib/Socket/Client/index.d.ts +3 -2
  7. package/lib/Socket/Client/index.js +3 -2
  8. package/lib/Socket/Client/{websocket.d.ts → web-socket-client.d.ts} +1 -1
  9. package/lib/Socket/Client/{websocket.js → web-socket-client.js} +2 -2
  10. package/lib/Socket/business.d.ts +3 -8
  11. package/lib/Socket/chats.d.ts +19 -21
  12. package/lib/Socket/chats.js +48 -51
  13. package/lib/Socket/groups.d.ts +26 -28
  14. package/lib/Socket/groups.js +1 -2
  15. package/lib/Socket/index.d.ts +3 -6
  16. package/lib/Socket/messages-recv.d.ts +3 -8
  17. package/lib/Socket/messages-recv.js +149 -308
  18. package/lib/Socket/messages-send.d.ts +26 -23
  19. package/lib/Socket/messages-send.js +166 -193
  20. package/lib/Socket/newsletter.d.ts +2 -2
  21. package/lib/Socket/newsletter.js +3 -3
  22. package/lib/Socket/registration.d.ts +3 -8
  23. package/lib/Socket/socket.d.ts +6 -8
  24. package/lib/Socket/socket.js +14 -19
  25. package/lib/Store/make-cache-manager-store.d.ts +2 -2
  26. package/lib/Store/make-ordered-dictionary.d.ts +1 -1
  27. package/lib/Types/Call.d.ts +1 -1
  28. package/lib/Types/Chat.d.ts +7 -12
  29. package/lib/Types/Events.d.ts +2 -17
  30. package/lib/Types/GroupMetadata.d.ts +1 -3
  31. package/lib/Types/Label.d.ts +0 -11
  32. package/lib/Types/Message.d.ts +328 -324
  33. package/lib/Types/Socket.d.ts +0 -7
  34. package/lib/Types/index.d.ts +0 -9
  35. package/lib/Utils/chat-utils.d.ts +4 -4
  36. package/lib/Utils/chat-utils.js +20 -41
  37. package/lib/Utils/crypto.d.ts +1 -1
  38. package/lib/Utils/crypto.js +2 -4
  39. package/lib/Utils/decode-wa-message.d.ts +0 -17
  40. package/lib/Utils/decode-wa-message.js +14 -42
  41. package/lib/Utils/generics.d.ts +10 -4
  42. package/lib/Utils/generics.js +14 -30
  43. package/lib/Utils/history.d.ts +2 -6
  44. package/lib/Utils/history.js +0 -3
  45. package/lib/Utils/messages.d.ts +1 -0
  46. package/lib/Utils/messages.js +39 -247
  47. package/lib/Utils/signal.d.ts +1 -2
  48. package/lib/Utils/signal.js +19 -11
  49. package/lib/Utils/use-multi-file-auth-state.js +3 -11
  50. package/lib/Utils/validate-connection.d.ts +2 -2
  51. package/lib/Utils/validate-connection.js +1 -1
  52. package/lib/WABinary/encode.d.ts +1 -1
  53. package/lib/WABinary/encode.js +10 -16
  54. package/lib/index.d.ts +11 -0
  55. package/lib/index.js +0 -1
  56. package/lib/index.ts +13 -0
  57. package/package.json +15 -27
  58. package/lib/Socket/Client/types.d.ts +0 -17
  59. package/lib/Socket/Client/types.js +0 -13
  60. package/lib/Socket/usync.d.ts +0 -37
  61. package/lib/Socket/usync.js +0 -70
  62. package/lib/Types/USync.d.ts +0 -25
  63. package/lib/Types/USync.js +0 -2
  64. package/lib/Utils/messages.js.bak +0 -1249
  65. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -9
  66. package/lib/WAUSync/Protocols/USyncContactProtocol.js +0 -32
  67. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -22
  68. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +0 -57
  69. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -12
  70. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +0 -30
  71. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -12
  72. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +0 -42
  73. package/lib/WAUSync/Protocols/index.d.ts +0 -4
  74. package/lib/WAUSync/Protocols/index.js +0 -20
  75. package/lib/WAUSync/USyncQuery.d.ts +0 -26
  76. package/lib/WAUSync/USyncQuery.js +0 -79
  77. package/lib/WAUSync/USyncUser.d.ts +0 -10
  78. package/lib/WAUSync/USyncUser.js +0 -22
  79. package/lib/WAUSync/index.d.ts +0 -3
  80. package/lib/WAUSync/index.js +0 -19
@@ -36,12 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.encodeBinaryNode = void 0;
37
37
  const constants = __importStar(require("./constants"));
38
38
  const jid_utils_1 = require("./jid-utils");
39
- const encodeBinaryNode = (node, opts = constants, buffer = [0]) => {
40
- const encoded = encodeBinaryNodeInner(node, opts, buffer);
41
- return Buffer.from(encoded);
42
- };
43
- exports.encodeBinaryNode = encodeBinaryNode;
44
- const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
39
+ const encodeBinaryNode = ({ tag, attrs, content }, opts = constants, buffer = [0]) => {
45
40
  const { TAGS, TOKEN_MAP } = opts;
46
41
  const pushByte = (value) => buffer.push(value & 0xff);
47
42
  const pushInt = (value, n, littleEndian = false) => {
@@ -50,11 +45,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
50
45
  buffer.push((value >> (curShift * 8)) & 0xff);
51
46
  }
52
47
  };
53
- const pushBytes = (bytes) => {
54
- for (const b of bytes) {
55
- buffer.push(b);
56
- }
57
- };
48
+ const pushBytes = (bytes) => (bytes.forEach(b => buffer.push(b)));
58
49
  const pushInt16 = (value) => {
59
50
  pushBytes([(value >> 8) & 0xff, value & 0xff]);
60
51
  };
@@ -156,7 +147,8 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
156
147
  if (str.length > TAGS.PACKED_MAX) {
157
148
  return false;
158
149
  }
159
- for (const char of str) {
150
+ for (let i = 0; i < str.length; i++) {
151
+ const char = str[i];
160
152
  const isInNibbleRange = char >= '0' && char <= '9';
161
153
  if (!isInNibbleRange && char !== '-' && char !== '.') {
162
154
  return false;
@@ -168,9 +160,10 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
168
160
  if (str.length > TAGS.PACKED_MAX) {
169
161
  return false;
170
162
  }
171
- for (const char of str) {
163
+ for (let i = 0; i < str.length; i++) {
164
+ const char = str[i];
172
165
  const isInNibbleRange = char >= '0' && char <= '9';
173
- if (!isInNibbleRange && !(char >= 'A' && char <= 'F')) {
166
+ if (!isInNibbleRange && !(char >= 'A' && char <= 'F') && !(char >= 'a' && char <= 'f')) {
174
167
  return false;
175
168
  }
176
169
  }
@@ -231,7 +224,7 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
231
224
  else if (Array.isArray(content)) {
232
225
  writeListStart(content.length);
233
226
  for (const item of content) {
234
- encodeBinaryNodeInner(item, opts, buffer);
227
+ (0, exports.encodeBinaryNode)(item, opts, buffer);
235
228
  }
236
229
  }
237
230
  else if (typeof content === 'undefined') {
@@ -240,5 +233,6 @@ const encodeBinaryNodeInner = ({ tag, attrs, content }, opts, buffer) => {
240
233
  else {
241
234
  throw new Error(`invalid children for header "${tag}": ${content} (${typeof content})`);
242
235
  }
243
- return buffer;
236
+ return Buffer.from(buffer);
244
237
  };
238
+ exports.encodeBinaryNode = encodeBinaryNode;
package/lib/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import makeWASocket from './Socket';
2
+ export * from '../WAProto';
3
+ export * from './Utils';
4
+ export * from './Types';
5
+ export * from './Store';
6
+ export * from './Defaults';
7
+ export * from './WABinary';
8
+ export * from './WAM';
9
+ export type WASocket = ReturnType<typeof makeWASocket>;
10
+ export { makeWASocket };
11
+ export default makeWASocket;
package/lib/index.js CHANGED
@@ -27,5 +27,4 @@ __exportStar(require("./Store"), exports);
27
27
  __exportStar(require("./Defaults"), exports);
28
28
  __exportStar(require("./WABinary"), exports);
29
29
  __exportStar(require("./WAM"), exports);
30
- __exportStar(require("./WAUSync"), exports);
31
30
  exports.default = Socket_1.default;
package/lib/index.ts ADDED
@@ -0,0 +1,13 @@
1
+ import makeWASocket from './Socket'
2
+
3
+ export * from '../WAProto'
4
+ export * from './Utils'
5
+ export * from './Types'
6
+ export * from './Store'
7
+ export * from './Defaults'
8
+ export * from './WABinary'
9
+ export * from './WAM'
10
+
11
+ export type WASocket = ReturnType<typeof makeWASocket>
12
+ export { makeWASocket }
13
+ export default makeWASocket
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jkt48connect-corp/baileys",
3
- "version": "7.3.1",
3
+ "version": "7.3.2",
4
4
  "description": "WhatsApp API",
5
5
  "keywords": [
6
6
  "Baileys",
@@ -24,7 +24,7 @@
24
24
  "url": ""
25
25
  },
26
26
  "license": "MIT",
27
- "author": "Adhiraj Singh",
27
+ "author": "Meta Platforms, Inc.",
28
28
  "main": "lib/index.js",
29
29
  "types": "lib/index.d.ts",
30
30
  "files": [
@@ -33,20 +33,6 @@
33
33
  "WASignalGroup/*.js"
34
34
  ],
35
35
  "scripts": {
36
- "build:all": "tsc && typedoc",
37
- "build:docs": "typedoc",
38
- "build:tsc": "tsc",
39
- "changelog:last": "conventional-changelog -p angular -r 2",
40
- "changelog:preview": "conventional-changelog -p angular -u",
41
- "changelog:update": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0",
42
- "example": "node --inspect -r ts-node/register Example/example.ts",
43
- "example:mobile": "node --inspect -r ts-node/register Example/example.ts --mobile",
44
- "gen:protobuf": "sh WAProto/GenerateStatics.sh",
45
- "lint": "eslint src --ext .js,.ts,.jsx,.tsx",
46
- "lint:fix": "eslint src --fix --ext .js,.ts,.jsx,.tsx",
47
- "prepack": "tsc",
48
- "prepare": "tsc",
49
- "release": "release-it",
50
36
  "test": "jest"
51
37
  },
52
38
  "dependencies": {
@@ -54,20 +40,22 @@
54
40
  "@hapi/boom": "^9.1.3",
55
41
  "async-lock": "^1.4.1",
56
42
  "audio-decode": "^2.1.3",
57
- "axios": "^1.3.3",
43
+ "axios": "^1.6.0",
44
+ "child_process": "^1.0.2",
58
45
  "cache-manager": "4.0.1",
59
46
  "futoin-hkdf": "^1.5.1",
60
47
  "libphonenumber-js": "^1.10.20",
61
- "libsignal": "github:WhiskeySockets/libsignal-node",
48
+ "libsignal": "npm:@meta.inc/libsignal@*",
49
+ "lodash": "^4.17.21",
62
50
  "music-metadata": "^7.12.3",
63
51
  "node-cache": "^5.1.2",
64
52
  "pino": "^7.0.0",
65
- "protobufjs": "^7.2.4",
66
- "uuid": "^9.0.0",
53
+ "protobufjs": "^6.11.3",
54
+ "uuid": "^10.0.0",
67
55
  "ws": "^8.13.0"
68
56
  },
69
57
  "devDependencies": {
70
- "@adiwajshing/eslint-config": "github:whiskeysockets/eslint-config",
58
+ "@adiwajshing/eslint-config": "npm:@meta.inc/eslint-config@*",
71
59
  "@types/got": "^9.6.11",
72
60
  "@types/jest": "^27.5.1",
73
61
  "@types/node": "^16.0.0",
@@ -77,22 +65,22 @@
77
65
  "eslint": "^8.0.0",
78
66
  "jest": "^27.0.6",
79
67
  "jimp": "^0.16.1",
80
- "link-preview-js": "^3.0.0",
68
+ "json": "^11.0.0",
69
+ "link-preview-js": "^3.0.5",
81
70
  "open": "^8.4.2",
82
71
  "qrcode-terminal": "^0.12.0",
83
72
  "release-it": "^15.10.3",
84
- "sharp": "^0.30.5",
73
+ "sharp": "^0.32.6",
85
74
  "ts-jest": "^27.0.3",
86
75
  "ts-node": "^10.8.1",
87
76
  "typedoc": "^0.24.7",
88
- "typescript": "^4.6.4",
89
- "json": "^11.0.0"
77
+ "typescript": "^4.6.4"
90
78
  },
91
79
  "peerDependencies": {
92
80
  "jimp": "^0.16.1",
93
- "link-preview-js": "^3.0.0",
81
+ "link-preview-js": "^3.0.12",
94
82
  "qrcode-terminal": "^0.12.0",
95
- "sharp": "^0.32.2"
83
+ "sharp": "^0.32.6"
96
84
  },
97
85
  "peerDependenciesMeta": {
98
86
  "jimp": {
@@ -1,17 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- import { EventEmitter } from 'events';
4
- import { URL } from 'url';
5
- import { SocketConfig } from '../../Types';
6
- export declare abstract class AbstractSocketClient extends EventEmitter {
7
- url: URL;
8
- config: SocketConfig;
9
- abstract get isOpen(): boolean;
10
- abstract get isClosed(): boolean;
11
- abstract get isClosing(): boolean;
12
- abstract get isConnecting(): boolean;
13
- constructor(url: URL, config: SocketConfig);
14
- abstract connect(): Promise<void>;
15
- abstract close(): Promise<void>;
16
- abstract send(str: Uint8Array | string, cb?: (err?: Error) => void): boolean;
17
- }
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractSocketClient = void 0;
4
- const events_1 = require("events");
5
- class AbstractSocketClient extends events_1.EventEmitter {
6
- constructor(url, config) {
7
- super();
8
- this.url = url;
9
- this.config = config;
10
- this.setMaxListeners(0);
11
- }
12
- }
13
- exports.AbstractSocketClient = AbstractSocketClient;
@@ -1,37 +0,0 @@
1
- /// <reference types="node" />
2
- import { Boom } from '@hapi/boom';
3
- import { SocketConfig } from '../Types';
4
- import { BinaryNode } from '../WABinary';
5
- import { USyncQuery } from '../WAUSync';
6
- export declare const makeUSyncSocket: (config: SocketConfig) => {
7
- executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
8
- type: "md";
9
- ws: any;
10
- ev: import("../Types").BaileysEventEmitter & {
11
- process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
12
- buffer(): void;
13
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
14
- flush(force?: boolean | undefined): boolean;
15
- isBuffering(): boolean;
16
- };
17
- authState: {
18
- creds: import("../Types").AuthenticationCreds;
19
- keys: import("../Types").SignalKeyStoreWithTransaction;
20
- };
21
- signalRepository: import("../Types").SignalRepository;
22
- user: import("../Types").Contact | undefined;
23
- generateMessageTag: () => string;
24
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
25
- waitForMessage: <T_1>(msgId: string, timeoutMs?: number | undefined) => Promise<T_1>;
26
- waitForSocketOpen: () => Promise<void>;
27
- sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
28
- sendNode: (frame: BinaryNode) => Promise<void>;
29
- logout: (msg?: string | undefined) => Promise<void>;
30
- end: (error: Error | undefined) => void;
31
- onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
32
- uploadPreKeys: (count?: number) => Promise<void>;
33
- uploadPreKeysToServerIfRequired: () => Promise<void>;
34
- requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
35
- waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
36
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
37
- };
@@ -1,70 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeUSyncSocket = void 0;
4
- const boom_1 = require("@hapi/boom");
5
- const WABinary_1 = require("../WABinary");
6
- const socket_1 = require("./socket");
7
- const makeUSyncSocket = (config) => {
8
- const sock = (0, socket_1.makeSocket)(config);
9
- const { generateMessageTag, query, } = sock;
10
- const executeUSyncQuery = async (usyncQuery) => {
11
- if (usyncQuery.protocols.length === 0) {
12
- throw new boom_1.Boom('USyncQuery must have at least one protocol');
13
- }
14
- // todo: validate users, throw WARNING on no valid users
15
- // variable below has only validated users
16
- const validUsers = usyncQuery.users;
17
- const userNodes = validUsers.map((user) => {
18
- return {
19
- tag: 'user',
20
- attrs: {
21
- jid: !user.phone ? user.id : undefined,
22
- },
23
- content: usyncQuery.protocols
24
- .map((a) => a.getUserElement(user))
25
- .filter(a => a !== null)
26
- };
27
- });
28
- const listNode = {
29
- tag: 'list',
30
- attrs: {},
31
- content: userNodes
32
- };
33
- const queryNode = {
34
- tag: 'query',
35
- attrs: {},
36
- content: usyncQuery.protocols.map((a) => a.getQueryElement())
37
- };
38
- const iq = {
39
- tag: 'iq',
40
- attrs: {
41
- to: WABinary_1.S_WHATSAPP_NET,
42
- type: 'get',
43
- xmlns: 'usync',
44
- },
45
- content: [
46
- {
47
- tag: 'usync',
48
- attrs: {
49
- context: usyncQuery.context,
50
- mode: usyncQuery.mode,
51
- sid: generateMessageTag(),
52
- last: 'true',
53
- index: '0',
54
- },
55
- content: [
56
- queryNode,
57
- listNode
58
- ]
59
- }
60
- ],
61
- };
62
- const result = await query(iq);
63
- return usyncQuery.parseUSyncQueryResult(result);
64
- };
65
- return {
66
- ...sock,
67
- executeUSyncQuery,
68
- };
69
- };
70
- exports.makeUSyncSocket = makeUSyncSocket;
@@ -1,25 +0,0 @@
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
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });