@yemo-dev/yebail 1.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 (106) hide show
  1. package/EXAMPLES.md +641 -0
  2. package/LICENSE +21 -0
  3. package/README.md +141 -0
  4. package/WAProto/GenerateStatics.sh +4 -0
  5. package/WAProto/WAProto.proto +4775 -0
  6. package/WAProto/index.js +116311 -0
  7. package/engine-requirements.js +10 -0
  8. package/lib/Defaults/index.js +142 -0
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Defaults/yebail-version.json +7 -0
  11. package/lib/Signal/Group/ciphertext-message.js +15 -0
  12. package/lib/Signal/Group/group-session-builder.js +64 -0
  13. package/lib/Signal/Group/group_cipher.js +96 -0
  14. package/lib/Signal/Group/index.js +57 -0
  15. package/lib/Signal/Group/keyhelper.js +55 -0
  16. package/lib/Signal/Group/queue-job.js +57 -0
  17. package/lib/Signal/Group/sender-chain-key.js +34 -0
  18. package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
  19. package/lib/Signal/Group/sender-key-message.js +69 -0
  20. package/lib/Signal/Group/sender-key-name.js +51 -0
  21. package/lib/Signal/Group/sender-key-record.js +53 -0
  22. package/lib/Signal/Group/sender-key-state.js +99 -0
  23. package/lib/Signal/Group/sender-message-key.js +29 -0
  24. package/lib/Signal/libsignal.js +196 -0
  25. package/lib/Signal/lid-mapping.js +148 -0
  26. package/lib/Socket/Client/index.js +18 -0
  27. package/lib/Socket/Client/types.js +13 -0
  28. package/lib/Socket/Client/websocket.js +72 -0
  29. package/lib/Socket/business.js +368 -0
  30. package/lib/Socket/chats.js +992 -0
  31. package/lib/Socket/communities.js +430 -0
  32. package/lib/Socket/groups.js +323 -0
  33. package/lib/Socket/index.js +10 -0
  34. package/lib/Socket/messages-recv.js +1133 -0
  35. package/lib/Socket/messages-send.js +992 -0
  36. package/lib/Socket/newsletter.js +250 -0
  37. package/lib/Socket/socket.js +631 -0
  38. package/lib/Socket/usync.js +70 -0
  39. package/lib/Store/index.js +8 -0
  40. package/lib/Store/make-in-memory-store.js +421 -0
  41. package/lib/Store/make-ordered-dictionary.js +81 -0
  42. package/lib/Store/object-repository.js +27 -0
  43. package/lib/Types/Auth.js +2 -0
  44. package/lib/Types/Call.js +2 -0
  45. package/lib/Types/Chat.js +4 -0
  46. package/lib/Types/Contact.js +2 -0
  47. package/lib/Types/Events.js +2 -0
  48. package/lib/Types/GroupMetadata.js +2 -0
  49. package/lib/Types/Label.js +27 -0
  50. package/lib/Types/LabelAssociation.js +9 -0
  51. package/lib/Types/Message.js +7 -0
  52. package/lib/Types/Newsletter.js +18 -0
  53. package/lib/Types/Product.js +2 -0
  54. package/lib/Types/Signal.js +2 -0
  55. package/lib/Types/Socket.js +2 -0
  56. package/lib/Types/State.js +2 -0
  57. package/lib/Types/USync.js +2 -0
  58. package/lib/Types/index.js +42 -0
  59. package/lib/Utils/auth-utils.js +188 -0
  60. package/lib/Utils/browser-utils.js +35 -0
  61. package/lib/Utils/business.js +230 -0
  62. package/lib/Utils/chat-utils.js +763 -0
  63. package/lib/Utils/crypto.js +187 -0
  64. package/lib/Utils/decode-wa-message.js +293 -0
  65. package/lib/Utils/event-buffer.js +514 -0
  66. package/lib/Utils/generics.js +453 -0
  67. package/lib/Utils/history.js +94 -0
  68. package/lib/Utils/index.js +37 -0
  69. package/lib/Utils/link-preview.js +121 -0
  70. package/lib/Utils/logger.js +7 -0
  71. package/lib/Utils/lt-hash.js +47 -0
  72. package/lib/Utils/make-mutex.js +43 -0
  73. package/lib/Utils/message-retry-manager.js +128 -0
  74. package/lib/Utils/messages-media.js +910 -0
  75. package/lib/Utils/messages.js +1129 -0
  76. package/lib/Utils/noise-handler.js +150 -0
  77. package/lib/Utils/process-message.js +448 -0
  78. package/lib/Utils/signal.js +150 -0
  79. package/lib/Utils/use-custom-auth-state.js +110 -0
  80. package/lib/Utils/use-multi-file-auth-state.js +43 -0
  81. package/lib/Utils/use-sqlite-auth-state.js +39 -0
  82. package/lib/Utils/validate-connection.js +237 -0
  83. package/lib/Utils/yebail-event-stream.js +55 -0
  84. package/lib/WABinary/constants.js +1303 -0
  85. package/lib/WABinary/decode.js +275 -0
  86. package/lib/WABinary/encode.js +250 -0
  87. package/lib/WABinary/generic-utils.js +110 -0
  88. package/lib/WABinary/index.js +21 -0
  89. package/lib/WABinary/jid-utils.js +136 -0
  90. package/lib/WABinary/types.js +2 -0
  91. package/lib/WAM/BinaryInfo.js +13 -0
  92. package/lib/WAM/constants.js +15350 -0
  93. package/lib/WAM/encode.js +155 -0
  94. package/lib/WAM/index.js +19 -0
  95. package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
  96. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
  97. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
  98. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
  99. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  100. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  101. package/lib/WAUSync/Protocols/index.js +20 -0
  102. package/lib/WAUSync/USyncQuery.js +89 -0
  103. package/lib/WAUSync/USyncUser.js +26 -0
  104. package/lib/WAUSync/index.js +19 -0
  105. package/lib/index.js +46 -0
  106. package/package.json +114 -0
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LIDMappingStore = void 0;
4
+ const WABinary_1 = require("../WABinary");
5
+ class LIDMappingStore {
6
+ constructor(keys, logger, pnToLIDFunc) {
7
+ this.mappingCache = new Map();
8
+ this.keys = keys;
9
+ this.pnToLIDFunc = pnToLIDFunc;
10
+ this.logger = logger || { trace: () => { }, debug: () => { }, warn: () => { } };
11
+ }
12
+ async storeLIDPNMappings(pairs) {
13
+ const pairMap = {};
14
+ for (const { lid, pn } of pairs) {
15
+ if (!(((0, WABinary_1.isLidUser)(lid) && (0, WABinary_1.isPnUser)(pn)) || ((0, WABinary_1.isPnUser)(lid) && (0, WABinary_1.isLidUser)(pn)))) {
16
+ this.logger.warn(`Invalid LID-PN mapping: ${lid}, ${pn}`);
17
+ continue;
18
+ }
19
+ const lidDecoded = (0, WABinary_1.jidDecode)(lid);
20
+ const pnDecoded = (0, WABinary_1.jidDecode)(pn);
21
+ if (!lidDecoded || !pnDecoded)
22
+ return;
23
+ const pnUser = pnDecoded.user;
24
+ const lidUser = lidDecoded.user;
25
+ let existingLidUser = this.mappingCache.get(`pn:${pnUser}`);
26
+ if (!existingLidUser) {
27
+ const stored = await this.keys.get('lid-mapping', [pnUser]);
28
+ existingLidUser = stored[pnUser];
29
+ if (existingLidUser) {
30
+ this.mappingCache.set(`pn:${pnUser}`, existingLidUser);
31
+ this.mappingCache.set(`lid:${existingLidUser}`, pnUser);
32
+ }
33
+ }
34
+ if (existingLidUser === lidUser) {
35
+ this.logger.debug({ pnUser, lidUser }, 'LID mapping already exists, skipping');
36
+ continue;
37
+ }
38
+ pairMap[pnUser] = lidUser;
39
+ }
40
+ if (!Object.keys(pairMap).length)
41
+ return;
42
+ await this.keys.transaction(async () => {
43
+ for (const [pnUser, lidUser] of Object.entries(pairMap)) {
44
+ await this.keys.set({
45
+ 'lid-mapping': {
46
+ [pnUser]: lidUser,
47
+ [`${lidUser}_reverse`]: pnUser
48
+ }
49
+ });
50
+ this.mappingCache.set(`pn:${pnUser}`, lidUser);
51
+ this.mappingCache.set(`lid:${lidUser}`, pnUser);
52
+ }
53
+ }, 'lid-mapping');
54
+ }
55
+ async getLIDForPN(pn) {
56
+ const rows = await this.getLIDsForPNs([pn]);
57
+ return rows?.[0]?.lid || null;
58
+ }
59
+ async getLIDsForPNs(pns) {
60
+ const usyncFetch = {};
61
+ const successfulPairs = {};
62
+ for (const pn of pns) {
63
+ if (!(0, WABinary_1.isPnUser)(pn) && !(0, WABinary_1.isHostedPnUser)(pn))
64
+ continue;
65
+ const decoded = (0, WABinary_1.jidDecode)(pn);
66
+ if (!decoded)
67
+ continue;
68
+ const pnUser = decoded.user;
69
+ let lidUser = this.mappingCache.get(`pn:${pnUser}`);
70
+ if (!lidUser) {
71
+ const stored = await this.keys.get('lid-mapping', [pnUser]);
72
+ lidUser = stored[pnUser];
73
+ if (lidUser) {
74
+ this.mappingCache.set(`pn:${pnUser}`, lidUser);
75
+ this.mappingCache.set(`lid:${lidUser}`, pnUser);
76
+ }
77
+ else {
78
+ const device = decoded.device || 0;
79
+ let normalizedPn = (0, WABinary_1.jidNormalizedUser)(pn);
80
+ if ((0, WABinary_1.isHostedPnUser)(normalizedPn)) {
81
+ normalizedPn = `${pnUser}@s.whatsapp.net`;
82
+ }
83
+ if (!usyncFetch[normalizedPn]) {
84
+ usyncFetch[normalizedPn] = [device];
85
+ }
86
+ else {
87
+ usyncFetch[normalizedPn].push(device);
88
+ }
89
+ continue;
90
+ }
91
+ }
92
+ lidUser = lidUser.toString();
93
+ if (!lidUser) {
94
+ this.logger.warn(`Invalid or empty LID user for PN ${pn}`);
95
+ return null;
96
+ }
97
+ const pnDevice = decoded.device !== undefined ? decoded.device : 0;
98
+ const deviceSpecificLid = `${lidUser}${pnDevice ? `:${pnDevice}` : ''}@${decoded.server === 'hosted' ? 'hosted.lid' : 'lid'}`;
99
+ successfulPairs[pn] = { lid: deviceSpecificLid, pn };
100
+ }
101
+ if (Object.keys(usyncFetch).length > 0) {
102
+ const result = await this.pnToLIDFunc?.(Object.keys(usyncFetch));
103
+ if (result && result.length > 0) {
104
+ await this.storeLIDPNMappings(result);
105
+ for (const pair of result) {
106
+ const pnDecoded = (0, WABinary_1.jidDecode)(pair.pn);
107
+ const pnUser = pnDecoded?.user;
108
+ if (!pnUser)
109
+ continue;
110
+ const lidUser = (0, WABinary_1.jidDecode)(pair.lid)?.user;
111
+ if (!lidUser)
112
+ continue;
113
+ for (const device of usyncFetch[pair.pn] || [0]) {
114
+ const deviceSpecificLid = `${lidUser}${device ? `:${device}` : ''}@${device === 99 ? 'hosted.lid' : 'lid'}`;
115
+ const deviceSpecificPn = `${pnUser}${device ? `:${device}` : ''}@${device === 99 ? 'hosted' : 's.whatsapp.net'}`;
116
+ successfulPairs[deviceSpecificPn] = { lid: deviceSpecificLid, pn: deviceSpecificPn };
117
+ }
118
+ }
119
+ }
120
+ else {
121
+ return null;
122
+ }
123
+ }
124
+ return Object.values(successfulPairs);
125
+ }
126
+ async getPNForLID(lid) {
127
+ if (!(0, WABinary_1.isLidUser)(lid) && !(0, WABinary_1.isHostedLidUser)(lid))
128
+ return null;
129
+ const decoded = (0, WABinary_1.jidDecode)(lid);
130
+ if (!decoded)
131
+ return null;
132
+ const lidUser = decoded.user;
133
+ let pnUser = this.mappingCache.get(`lid:${lidUser}`);
134
+ if (!pnUser || typeof pnUser !== 'string') {
135
+ const stored = await this.keys.get('lid-mapping', [`${lidUser}_reverse`]);
136
+ pnUser = stored[`${lidUser}_reverse`];
137
+ if (!pnUser || typeof pnUser !== 'string') {
138
+ this.logger.trace(`No reverse mapping found for LID user: ${lidUser}`);
139
+ return null;
140
+ }
141
+ this.mappingCache.set(`lid:${lidUser}`, pnUser);
142
+ }
143
+ const lidDevice = decoded.device !== undefined ? decoded.device : 0;
144
+ const pnJid = `${pnUser}:${lidDevice}@${decoded.domainType === WABinary_1.WAJIDDomains.HOSTED_LID ? 'hosted' : 's.whatsapp.net'}`;
145
+ return pnJid;
146
+ }
147
+ }
148
+ exports.LIDMappingStore = LIDMappingStore;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./types"), exports);
18
+ __exportStar(require("./websocket"), exports);
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,72 @@
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.WebSocketClient = void 0;
7
+ const ws_1 = __importDefault(require("ws"));
8
+ const Defaults_1 = require("../../Defaults");
9
+ const types_1 = require("./types");
10
+ class WebSocketClient extends types_1.AbstractSocketClient {
11
+ constructor() {
12
+ super(...arguments);
13
+ this.socket = null;
14
+ }
15
+ get isOpen() {
16
+ var _a;
17
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.OPEN;
18
+ }
19
+ get isClosed() {
20
+ var _a;
21
+ return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSED;
22
+ }
23
+ get isClosing() {
24
+ var _a;
25
+ return this.socket === null || ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CLOSING;
26
+ }
27
+ get isConnecting() {
28
+ var _a;
29
+ return ((_a = this.socket) === null || _a === void 0 ? void 0 : _a.readyState) === ws_1.default.CONNECTING;
30
+ }
31
+ async connect() {
32
+ var _a, _b;
33
+ if (this.socket) {
34
+ return;
35
+ }
36
+ this.socket = new ws_1.default(this.url, {
37
+ origin: Defaults_1.DEFAULT_ORIGIN,
38
+ headers: (_a = this.config.options) === null || _a === void 0 ? void 0 : _a.headers,
39
+ handshakeTimeout: this.config.connectTimeoutMs,
40
+ timeout: this.config.connectTimeoutMs,
41
+ agent: this.config.agent,
42
+ });
43
+ this.socket.setMaxListeners(0);
44
+ const events = ['close', 'error', 'upgrade', 'message', 'open', 'ping', 'pong', 'unexpected-response'];
45
+ for (const event of events) {
46
+ (_b = this.socket) === null || _b === void 0 ? void 0 : _b.on(event, (...args) => this.emit(event, ...args));
47
+ }
48
+ }
49
+ async close() {
50
+ if (!this.socket) {
51
+ return;
52
+ }
53
+ this.socket.close();
54
+ this.socket = null;
55
+ }
56
+ async restart() {
57
+ if (this.socket) {
58
+ await new Promise(resolve => {
59
+ this.socket.once('close', resolve);
60
+ this.socket.terminate();
61
+ });
62
+ this.socket = null;
63
+ }
64
+ await this.connect();
65
+ }
66
+ send(str, cb) {
67
+ var _a;
68
+ (_a = this.socket) === null || _a === void 0 ? void 0 : _a.send(str, cb);
69
+ return true;
70
+ }
71
+ }
72
+ exports.WebSocketClient = WebSocketClient;
@@ -0,0 +1,368 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.makeBusinessSocket = void 0;
4
+ const business_1 = require("../Utils/business");
5
+ const WABinary_1 = require("../WABinary");
6
+ const generic_utils_1 = require("../WABinary/generic-utils");
7
+ const messages_recv_1 = require("./messages-recv");
8
+ const messages_media_1 = require("../Utils/messages-media");
9
+ const makeBusinessSocket = (config) => {
10
+ const sock = (0, messages_recv_1.makeMessagesRecvSocket)(config);
11
+ const { authState, query, waUploadToServer } = sock;
12
+ const updateBussinesProfile = async (args) => {
13
+ const node = [];
14
+ const simpleFields = ['address', 'email', 'description'];
15
+ for (const key of simpleFields) {
16
+ if (args[key] !== undefined && args[key] !== null) {
17
+ node.push({ tag: key, attrs: {}, content: args[key] });
18
+ }
19
+ }
20
+ if (args.websites !== undefined) {
21
+ node.push(...args.websites.map(website => ({ tag: 'website', attrs: {}, content: website })));
22
+ }
23
+ if (args.hours !== undefined) {
24
+ node.push({
25
+ tag: 'business_hours',
26
+ attrs: { timezone: args.hours.timezone },
27
+ content: args.hours.days.map(dayConfig => {
28
+ const base = {
29
+ tag: 'business_hours_config',
30
+ attrs: {
31
+ day_of_week: dayConfig.day,
32
+ mode: dayConfig.mode
33
+ }
34
+ };
35
+ if (dayConfig.mode === 'specific_hours') {
36
+ return {
37
+ ...base,
38
+ attrs: {
39
+ ...base.attrs,
40
+ open_time: dayConfig.openTimeInMinutes,
41
+ close_time: dayConfig.closeTimeInMinutes
42
+ }
43
+ };
44
+ }
45
+ return base;
46
+ })
47
+ });
48
+ }
49
+ return query({
50
+ tag: 'iq',
51
+ attrs: {
52
+ to: WABinary_1.S_WHATSAPP_NET,
53
+ type: 'set',
54
+ xmlns: 'w:biz'
55
+ },
56
+ content: [
57
+ {
58
+ tag: 'business_profile',
59
+ attrs: { v: '3', mutation_type: 'delta' },
60
+ content: node
61
+ }
62
+ ]
63
+ });
64
+ };
65
+ const updateCoverPhoto = async (photo) => {
66
+ const { fileSha256, filePath } = await (0, messages_media_1.getRawMediaUploadData)(photo, 'biz-cover-photo', config.logger);
67
+ const fileSha256B64 = fileSha256.toString('base64');
68
+ const { meta_hmac, fbid, ts } = await waUploadToServer(filePath, {
69
+ fileEncSha256B64: fileSha256B64,
70
+ mediaType: 'biz-cover-photo'
71
+ });
72
+ await query({
73
+ tag: 'iq',
74
+ attrs: {
75
+ to: WABinary_1.S_WHATSAPP_NET,
76
+ type: 'set',
77
+ xmlns: 'w:biz'
78
+ },
79
+ content: [
80
+ {
81
+ tag: 'business_profile',
82
+ attrs: { v: '3', mutation_type: 'delta' },
83
+ content: [
84
+ {
85
+ tag: 'cover_photo',
86
+ attrs: { id: String(fbid), op: 'update', token: meta_hmac, ts: String(ts) }
87
+ }
88
+ ]
89
+ }
90
+ ]
91
+ });
92
+ return fbid;
93
+ };
94
+ const removeCoverPhoto = async (id) => {
95
+ return query({
96
+ tag: 'iq',
97
+ attrs: {
98
+ to: WABinary_1.S_WHATSAPP_NET,
99
+ type: 'set',
100
+ xmlns: 'w:biz'
101
+ },
102
+ content: [
103
+ {
104
+ tag: 'business_profile',
105
+ attrs: { v: '3', mutation_type: 'delta' },
106
+ content: [
107
+ {
108
+ tag: 'cover_photo',
109
+ attrs: { op: 'delete', id }
110
+ }
111
+ ]
112
+ }
113
+ ]
114
+ });
115
+ };
116
+ const getCatalog = async ({ jid, limit, cursor }) => {
117
+ var _a;
118
+ jid = jid || ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id);
119
+ jid = (0, WABinary_1.jidNormalizedUser)(jid);
120
+ const queryParamNodes = [
121
+ {
122
+ tag: 'limit',
123
+ attrs: {},
124
+ content: Buffer.from((limit || 10).toString())
125
+ },
126
+ {
127
+ tag: 'width',
128
+ attrs: {},
129
+ content: Buffer.from('100')
130
+ },
131
+ {
132
+ tag: 'height',
133
+ attrs: {},
134
+ content: Buffer.from('100')
135
+ },
136
+ ];
137
+ if (cursor) {
138
+ queryParamNodes.push({
139
+ tag: 'after',
140
+ attrs: {},
141
+ content: cursor
142
+ });
143
+ }
144
+ const result = await query({
145
+ tag: 'iq',
146
+ attrs: {
147
+ to: WABinary_1.S_WHATSAPP_NET,
148
+ type: 'get',
149
+ xmlns: 'w:biz:catalog'
150
+ },
151
+ content: [
152
+ {
153
+ tag: 'product_catalog',
154
+ attrs: {
155
+ jid,
156
+ 'allow_shop_source': 'true'
157
+ },
158
+ content: queryParamNodes
159
+ }
160
+ ]
161
+ });
162
+ return (0, business_1.parseCatalogNode)(result);
163
+ };
164
+ const getCollections = async (jid, limit = 51) => {
165
+ var _a;
166
+ jid = jid || ((_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.id);
167
+ jid = (0, WABinary_1.jidNormalizedUser)(jid);
168
+ const result = await query({
169
+ tag: 'iq',
170
+ attrs: {
171
+ to: WABinary_1.S_WHATSAPP_NET,
172
+ type: 'get',
173
+ xmlns: 'w:biz:catalog',
174
+ 'smax_id': '35'
175
+ },
176
+ content: [
177
+ {
178
+ tag: 'collections',
179
+ attrs: {
180
+ 'biz_jid': jid,
181
+ },
182
+ content: [
183
+ {
184
+ tag: 'collection_limit',
185
+ attrs: {},
186
+ content: Buffer.from(limit.toString())
187
+ },
188
+ {
189
+ tag: 'item_limit',
190
+ attrs: {},
191
+ content: Buffer.from(limit.toString())
192
+ },
193
+ {
194
+ tag: 'width',
195
+ attrs: {},
196
+ content: Buffer.from('100')
197
+ },
198
+ {
199
+ tag: 'height',
200
+ attrs: {},
201
+ content: Buffer.from('100')
202
+ }
203
+ ]
204
+ }
205
+ ]
206
+ });
207
+ return (0, business_1.parseCollectionsNode)(result);
208
+ };
209
+ const getOrderDetails = async (orderId, tokenBase64) => {
210
+ const result = await query({
211
+ tag: 'iq',
212
+ attrs: {
213
+ to: WABinary_1.S_WHATSAPP_NET,
214
+ type: 'get',
215
+ xmlns: 'fb:thrift_iq',
216
+ 'smax_id': '5'
217
+ },
218
+ content: [
219
+ {
220
+ tag: 'order',
221
+ attrs: {
222
+ op: 'get',
223
+ id: orderId
224
+ },
225
+ content: [
226
+ {
227
+ tag: 'image_dimensions',
228
+ attrs: {},
229
+ content: [
230
+ {
231
+ tag: 'width',
232
+ attrs: {},
233
+ content: Buffer.from('100')
234
+ },
235
+ {
236
+ tag: 'height',
237
+ attrs: {},
238
+ content: Buffer.from('100')
239
+ }
240
+ ]
241
+ },
242
+ {
243
+ tag: 'token',
244
+ attrs: {},
245
+ content: Buffer.from(tokenBase64)
246
+ }
247
+ ]
248
+ }
249
+ ]
250
+ });
251
+ return (0, business_1.parseOrderDetailsNode)(result);
252
+ };
253
+ const productUpdate = async (productId, update) => {
254
+ update = await (0, business_1.uploadingNecessaryImagesOfProduct)(update, waUploadToServer);
255
+ const editNode = (0, business_1.toProductNode)(productId, update);
256
+ const result = await query({
257
+ tag: 'iq',
258
+ attrs: {
259
+ to: WABinary_1.S_WHATSAPP_NET,
260
+ type: 'set',
261
+ xmlns: 'w:biz:catalog'
262
+ },
263
+ content: [
264
+ {
265
+ tag: 'product_catalog_edit',
266
+ attrs: { v: '1' },
267
+ content: [
268
+ editNode,
269
+ {
270
+ tag: 'width',
271
+ attrs: {},
272
+ content: '100'
273
+ },
274
+ {
275
+ tag: 'height',
276
+ attrs: {},
277
+ content: '100'
278
+ }
279
+ ]
280
+ }
281
+ ]
282
+ });
283
+ const productCatalogEditNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_edit');
284
+ const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogEditNode, 'product');
285
+ return (0, business_1.parseProductNode)(productNode);
286
+ };
287
+ const productCreate = async (create) => {
288
+ // ensure isHidden is defined
289
+ create.isHidden = !!create.isHidden;
290
+ create = await (0, business_1.uploadingNecessaryImagesOfProduct)(create, waUploadToServer);
291
+ const createNode = (0, business_1.toProductNode)(undefined, create);
292
+ const result = await query({
293
+ tag: 'iq',
294
+ attrs: {
295
+ to: WABinary_1.S_WHATSAPP_NET,
296
+ type: 'set',
297
+ xmlns: 'w:biz:catalog'
298
+ },
299
+ content: [
300
+ {
301
+ tag: 'product_catalog_add',
302
+ attrs: { v: '1' },
303
+ content: [
304
+ createNode,
305
+ {
306
+ tag: 'width',
307
+ attrs: {},
308
+ content: '100'
309
+ },
310
+ {
311
+ tag: 'height',
312
+ attrs: {},
313
+ content: '100'
314
+ }
315
+ ]
316
+ }
317
+ ]
318
+ });
319
+ const productCatalogAddNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_add');
320
+ const productNode = (0, generic_utils_1.getBinaryNodeChild)(productCatalogAddNode, 'product');
321
+ return (0, business_1.parseProductNode)(productNode);
322
+ };
323
+ const productDelete = async (productIds) => {
324
+ const result = await query({
325
+ tag: 'iq',
326
+ attrs: {
327
+ to: WABinary_1.S_WHATSAPP_NET,
328
+ type: 'set',
329
+ xmlns: 'w:biz:catalog'
330
+ },
331
+ content: [
332
+ {
333
+ tag: 'product_catalog_delete',
334
+ attrs: { v: '1' },
335
+ content: productIds.map(id => ({
336
+ tag: 'product',
337
+ attrs: {},
338
+ content: [
339
+ {
340
+ tag: 'id',
341
+ attrs: {},
342
+ content: Buffer.from(id)
343
+ }
344
+ ]
345
+ }))
346
+ }
347
+ ]
348
+ });
349
+ const productCatalogDelNode = (0, generic_utils_1.getBinaryNodeChild)(result, 'product_catalog_delete');
350
+ return {
351
+ deleted: +((productCatalogDelNode === null || productCatalogDelNode === void 0 ? void 0 : productCatalogDelNode.attrs.deleted_count) || 0)
352
+ };
353
+ };
354
+ return {
355
+ ...sock,
356
+ logger: config.logger,
357
+ getOrderDetails,
358
+ getCatalog,
359
+ getCollections,
360
+ productCreate,
361
+ productDelete,
362
+ productUpdate,
363
+ updateBussinesProfile,
364
+ updateCoverPhoto,
365
+ removeCoverPhoto
366
+ };
367
+ };
368
+ exports.makeBusinessSocket = makeBusinessSocket;