@xbibzlibrary/whatsbibz 1.3.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 (260) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/LICENSE +22 -0
  3. package/LICENSE.upstream +21 -0
  4. package/README.md +280 -0
  5. package/VERIFIKASI-IDENTITAS-2026-09-03.md +138 -0
  6. package/WAProto/GenerateStatics.sh +3 -0
  7. package/WAProto/WAProto.proto +6035 -0
  8. package/WAProto/fix-imports.js +81 -0
  9. package/WAProto/index.d.ts +15314 -0
  10. package/WAProto/index.js +132326 -0
  11. package/assets/logo/README.md +21 -0
  12. package/assets/logo/png/banner-1200x360.png +0 -0
  13. package/assets/logo/png/icon-1024.png +0 -0
  14. package/assets/logo/png/icon-128.png +0 -0
  15. package/assets/logo/png/icon-16.png +0 -0
  16. package/assets/logo/png/icon-24.png +0 -0
  17. package/assets/logo/png/icon-256.png +0 -0
  18. package/assets/logo/png/icon-32.png +0 -0
  19. package/assets/logo/png/icon-48.png +0 -0
  20. package/assets/logo/png/icon-512.png +0 -0
  21. package/assets/logo/png/icon-64.png +0 -0
  22. package/assets/logo/png/mark-512.png +0 -0
  23. package/assets/logo/preview.png +0 -0
  24. package/assets/logo/whatsbibz.ico +0 -0
  25. package/lib/BibzWhats/client.d.ts +95 -0
  26. package/lib/BibzWhats/client.js +501 -0
  27. package/lib/BibzWhats/device-identity.d.ts +60 -0
  28. package/lib/BibzWhats/device-identity.js +234 -0
  29. package/lib/BibzWhats/extract.d.ts +29 -0
  30. package/lib/BibzWhats/extract.js +115 -0
  31. package/lib/BibzWhats/index.d.ts +7 -0
  32. package/lib/BibzWhats/index.js +8 -0
  33. package/lib/BibzWhats/jid.d.ts +22 -0
  34. package/lib/BibzWhats/jid.js +98 -0
  35. package/lib/BibzWhats/pairing.d.ts +35 -0
  36. package/lib/BibzWhats/pairing.js +186 -0
  37. package/lib/BibzWhats/send.d.ts +9 -0
  38. package/lib/BibzWhats/send.js +107 -0
  39. package/lib/BibzWhats/version.d.ts +6 -0
  40. package/lib/BibzWhats/version.js +7 -0
  41. package/lib/Defaults/index.d.ts +73 -0
  42. package/lib/Defaults/index.js +141 -0
  43. package/lib/Modded/message_builder.d.ts +15 -0
  44. package/lib/Modded/message_builder.js +2330 -0
  45. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  46. package/lib/Signal/Group/ciphertext-message.js +11 -0
  47. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  48. package/lib/Signal/Group/group-session-builder.js +29 -0
  49. package/lib/Signal/Group/group_cipher.d.ts +16 -0
  50. package/lib/Signal/Group/group_cipher.js +81 -0
  51. package/lib/Signal/Group/index.d.ts +11 -0
  52. package/lib/Signal/Group/index.js +11 -0
  53. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  54. package/lib/Signal/Group/keyhelper.js +17 -0
  55. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  56. package/lib/Signal/Group/sender-chain-key.js +25 -0
  57. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  58. package/lib/Signal/Group/sender-key-distribution-message.js +62 -0
  59. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  60. package/lib/Signal/Group/sender-key-message.js +65 -0
  61. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  62. package/lib/Signal/Group/sender-key-name.js +47 -0
  63. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  64. package/lib/Signal/Group/sender-key-record.js +40 -0
  65. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  66. package/lib/Signal/Group/sender-key-state.js +83 -0
  67. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  68. package/lib/Signal/Group/sender-message-key.js +25 -0
  69. package/lib/Signal/libsignal.d.ts +4 -0
  70. package/lib/Signal/libsignal.js +406 -0
  71. package/lib/Signal/lid-mapping.d.ts +18 -0
  72. package/lib/Signal/lid-mapping.js +276 -0
  73. package/lib/Socket/Client/index.d.ts +2 -0
  74. package/lib/Socket/Client/index.js +2 -0
  75. package/lib/Socket/Client/types.d.ts +15 -0
  76. package/lib/Socket/Client/types.js +10 -0
  77. package/lib/Socket/Client/websocket.d.ts +12 -0
  78. package/lib/Socket/Client/websocket.js +53 -0
  79. package/lib/Socket/business.d.ts +537 -0
  80. package/lib/Socket/business.js +421 -0
  81. package/lib/Socket/chats.d.ts +110 -0
  82. package/lib/Socket/chats.js +1006 -0
  83. package/lib/Socket/communities.d.ts +646 -0
  84. package/lib/Socket/communities.js +430 -0
  85. package/lib/Socket/engine.d.ts +129 -0
  86. package/lib/Socket/engine.js +767 -0
  87. package/lib/Socket/groups.d.ts +149 -0
  88. package/lib/Socket/groups.js +326 -0
  89. package/lib/Socket/index.d.ts +637 -0
  90. package/lib/Socket/index.js +14 -0
  91. package/lib/Socket/messages-recv.d.ts +239 -0
  92. package/lib/Socket/messages-recv.js +1307 -0
  93. package/lib/Socket/messages-send.d.ts +580 -0
  94. package/lib/Socket/messages-send.js +1639 -0
  95. package/lib/Socket/mex.d.ts +2 -0
  96. package/lib/Socket/mex.js +47 -0
  97. package/lib/Socket/newsletter.d.ts +176 -0
  98. package/lib/Socket/newsletter.js +456 -0
  99. package/lib/Socket/socket.d.ts +56 -0
  100. package/lib/Socket/socket.js +998 -0
  101. package/lib/Types/Auth.d.ts +115 -0
  102. package/lib/Types/Auth.js +1 -0
  103. package/lib/Types/Bussines.d.ts +36 -0
  104. package/lib/Types/Bussines.js +1 -0
  105. package/lib/Types/Call.d.ts +14 -0
  106. package/lib/Types/Call.js +1 -0
  107. package/lib/Types/Chat.d.ts +124 -0
  108. package/lib/Types/Chat.js +7 -0
  109. package/lib/Types/Contact.d.ts +23 -0
  110. package/lib/Types/Contact.js +1 -0
  111. package/lib/Types/Events.d.ts +241 -0
  112. package/lib/Types/Events.js +1 -0
  113. package/lib/Types/GroupMetadata.d.ts +67 -0
  114. package/lib/Types/GroupMetadata.js +1 -0
  115. package/lib/Types/Label.d.ts +46 -0
  116. package/lib/Types/Label.js +24 -0
  117. package/lib/Types/LabelAssociation.d.ts +29 -0
  118. package/lib/Types/LabelAssociation.js +6 -0
  119. package/lib/Types/Message.d.ts +427 -0
  120. package/lib/Types/Message.js +10 -0
  121. package/lib/Types/Newsletter.d.ts +134 -0
  122. package/lib/Types/Newsletter.js +30 -0
  123. package/lib/Types/Product.d.ts +78 -0
  124. package/lib/Types/Product.js +1 -0
  125. package/lib/Types/Signal.d.ts +77 -0
  126. package/lib/Types/Signal.js +1 -0
  127. package/lib/Types/Socket.d.ts +173 -0
  128. package/lib/Types/Socket.js +2 -0
  129. package/lib/Types/State.d.ts +38 -0
  130. package/lib/Types/State.js +12 -0
  131. package/lib/Types/USync.d.ts +25 -0
  132. package/lib/Types/USync.js +1 -0
  133. package/lib/Types/index.d.ts +75 -0
  134. package/lib/Types/index.js +32 -0
  135. package/lib/Utils/auth-utils.d.ts +18 -0
  136. package/lib/Utils/auth-utils.js +289 -0
  137. package/lib/Utils/browser-utils.d.ts +3 -0
  138. package/lib/Utils/browser-utils.js +47 -0
  139. package/lib/Utils/business.d.ts +22 -0
  140. package/lib/Utils/business.js +230 -0
  141. package/lib/Utils/chat-utils.d.ts +69 -0
  142. package/lib/Utils/chat-utils.js +811 -0
  143. package/lib/Utils/companion-reg-client-utils.d.ts +20 -0
  144. package/lib/Utils/companion-reg-client-utils.js +66 -0
  145. package/lib/Utils/crypto.d.ts +41 -0
  146. package/lib/Utils/crypto.js +117 -0
  147. package/lib/Utils/decode-wa-message.d.ts +47 -0
  148. package/lib/Utils/decode-wa-message.js +282 -0
  149. package/lib/Utils/event-buffer.d.ts +35 -0
  150. package/lib/Utils/event-buffer.js +590 -0
  151. package/lib/Utils/generics.d.ts +90 -0
  152. package/lib/Utils/generics.js +384 -0
  153. package/lib/Utils/history.d.ts +21 -0
  154. package/lib/Utils/history.js +130 -0
  155. package/lib/Utils/identity-change-handler.d.ts +36 -0
  156. package/lib/Utils/identity-change-handler.js +48 -0
  157. package/lib/Utils/index.d.ts +25 -0
  158. package/lib/Utils/index.js +24 -0
  159. package/lib/Utils/link-preview.d.ts +20 -0
  160. package/lib/Utils/link-preview.js +84 -0
  161. package/lib/Utils/logger.d.ts +12 -0
  162. package/lib/Utils/logger.js +2 -0
  163. package/lib/Utils/lt-hash.d.ts +10 -0
  164. package/lib/Utils/lt-hash.js +7 -0
  165. package/lib/Utils/make-mutex.d.ts +8 -0
  166. package/lib/Utils/make-mutex.js +32 -0
  167. package/lib/Utils/message-retry-manager.d.ts +109 -0
  168. package/lib/Utils/message-retry-manager.js +224 -0
  169. package/lib/Utils/messages-media.d.ts +129 -0
  170. package/lib/Utils/messages-media.js +784 -0
  171. package/lib/Utils/messages.d.ts +90 -0
  172. package/lib/Utils/messages.js +1240 -0
  173. package/lib/Utils/noise-handler.d.ts +19 -0
  174. package/lib/Utils/noise-handler.js +200 -0
  175. package/lib/Utils/offline-node-processor.d.ts +16 -0
  176. package/lib/Utils/offline-node-processor.js +39 -0
  177. package/lib/Utils/platform-identity.d.ts +14 -0
  178. package/lib/Utils/platform-identity.js +148 -0
  179. package/lib/Utils/pre-key-manager.d.ts +27 -0
  180. package/lib/Utils/pre-key-manager.js +105 -0
  181. package/lib/Utils/process-message.d.ts +59 -0
  182. package/lib/Utils/process-message.js +544 -0
  183. package/lib/Utils/reporting-utils.d.ts +10 -0
  184. package/lib/Utils/reporting-utils.js +257 -0
  185. package/lib/Utils/rich-messages.d.ts +276 -0
  186. package/lib/Utils/rich-messages.js +1143 -0
  187. package/lib/Utils/signal.d.ts +33 -0
  188. package/lib/Utils/signal.js +158 -0
  189. package/lib/Utils/stanza-ack.d.ts +10 -0
  190. package/lib/Utils/stanza-ack.js +37 -0
  191. package/lib/Utils/sticker-pack.d.ts +10 -0
  192. package/lib/Utils/sticker-pack.js +111 -0
  193. package/lib/Utils/sync-action-utils.d.ts +18 -0
  194. package/lib/Utils/sync-action-utils.js +47 -0
  195. package/lib/Utils/tc-token-utils.d.ts +8 -0
  196. package/lib/Utils/tc-token-utils.js +45 -0
  197. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  198. package/lib/Utils/use-multi-file-auth-state.js +120 -0
  199. package/lib/Utils/validate-connection.d.ts +10 -0
  200. package/lib/Utils/validate-connection.js +222 -0
  201. package/lib/VoIP/audio-feeder.d.ts +15 -0
  202. package/lib/VoIP/audio-feeder.js +136 -0
  203. package/lib/VoIP/index.d.ts +12 -0
  204. package/lib/VoIP/index.js +282 -0
  205. package/lib/VoIP/relay-transport.d.ts +43 -0
  206. package/lib/VoIP/relay-transport.js +559 -0
  207. package/lib/VoIP/signaling.js +603 -0
  208. package/lib/VoIP/types.d.ts +69 -0
  209. package/lib/VoIP/types.js +17 -0
  210. package/lib/VoIP/wasm-engine.d.ts +103 -0
  211. package/lib/VoIP/wasm-engine.js +1214 -0
  212. package/lib/VoIP/worker-bootstrap.js +1042 -0
  213. package/lib/WABinary/constants.d.ts +27 -0
  214. package/lib/WABinary/constants.js +1300 -0
  215. package/lib/WABinary/decode.d.ts +6 -0
  216. package/lib/WABinary/decode.js +261 -0
  217. package/lib/WABinary/encode.d.ts +2 -0
  218. package/lib/WABinary/encode.js +219 -0
  219. package/lib/WABinary/generic-utils.d.ts +16 -0
  220. package/lib/WABinary/generic-utils.js +190 -0
  221. package/lib/WABinary/index.d.ts +5 -0
  222. package/lib/WABinary/index.js +5 -0
  223. package/lib/WABinary/jid-utils.d.ts +47 -0
  224. package/lib/WABinary/jid-utils.js +95 -0
  225. package/lib/WABinary/types.d.ts +18 -0
  226. package/lib/WABinary/types.js +1 -0
  227. package/lib/WAM/BinaryInfo.d.ts +8 -0
  228. package/lib/WAM/BinaryInfo.js +9 -0
  229. package/lib/WAM/constants.d.ts +39 -0
  230. package/lib/WAM/constants.js +22852 -0
  231. package/lib/WAM/encode.d.ts +2 -0
  232. package/lib/WAM/encode.js +149 -0
  233. package/lib/WAM/index.d.ts +3 -0
  234. package/lib/WAM/index.js +3 -0
  235. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  236. package/lib/WAUSync/Protocols/USyncContactProtocol.js +28 -0
  237. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  238. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +53 -0
  239. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  240. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +26 -0
  241. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  242. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +37 -0
  243. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  244. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +50 -0
  245. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +9 -0
  246. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +28 -0
  247. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  248. package/lib/WAUSync/Protocols/index.js +4 -0
  249. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  250. package/lib/WAUSync/USyncQuery.js +93 -0
  251. package/lib/WAUSync/USyncUser.d.ts +12 -0
  252. package/lib/WAUSync/USyncUser.js +22 -0
  253. package/lib/WAUSync/index.d.ts +3 -0
  254. package/lib/WAUSync/index.js +3 -0
  255. package/lib/assets/wasm/loader.js +5 -0
  256. package/lib/assets/wasm/whatsapp.wasm +0 -0
  257. package/lib/assets/wasm/worker-modules.js +273 -0
  258. package/lib/index.d.ts +21 -0
  259. package/lib/index.js +22 -0
  260. package/package.json +111 -0
@@ -0,0 +1,186 @@
1
+ // BibzWhats — PairingController
2
+ // Meminta pairing code (custom 8 karakter atau acak bawaan) dengan disiplin:
3
+ // • satu request in-flight pada satu waktu
4
+ // • refresh berjeda panjang (default 150 dtk) agar kode yang sedang diketik
5
+ // di HP tidak hangus di tengah percobaan
6
+ // • custom code ditolak server → fallback SEKALI ke kode acak
7
+ // • rate-limit (428/429) → backoff eksponensial sampai PAIRING_BACKOFF_MAX_MS
8
+ // • berhenti otomatis begitu creds.registered = true
9
+
10
+ export const PAIRING_REFRESH_MS = 150000;
11
+ export const PAIRING_BACKOFF_MAX_MS = 600000;
12
+
13
+ export function normalizePairingCode(value) {
14
+ const normalized = String(value ?? '').trim().toUpperCase();
15
+ return /^[A-Z0-9]{8}$/.test(normalized) ? normalized : '';
16
+ }
17
+
18
+ /**
19
+ * Kode error dari server. Boom hasil assertNodeErrorFree menyimpan kode stanza
20
+ * WA di `error.data` (mis. 400 bad-request, 429 rate-overlimit), sedangkan
21
+ * statusCode Boom-nya 500 generik — jadi keduanya harus dicek.
22
+ */
23
+ export function pairingErrorCode(error) {
24
+ const fromData = typeof error?.data === 'number' ? error.data : undefined;
25
+ const status = error?.output?.statusCode ?? error?.statusCode ?? error?.status;
26
+ return fromData ?? (status && status !== 500 ? status : undefined);
27
+ }
28
+
29
+ export function isRateLimitError(error) {
30
+ const code = pairingErrorCode(error);
31
+ return code === 428 || code === 429 || /rate[- ]?overlimit|rate.?limit|too many|428|429/i.test(String(error?.message || error));
32
+ }
33
+
34
+ export function isCustomPairingError(error) {
35
+ const code = pairingErrorCode(error);
36
+ return code === 422 || /custom pairing code|pairing code.*(invalid|reject|unsupported)|invalid.*pairing/i.test(String(error?.message || error));
37
+ }
38
+
39
+ /** 400 bad-request pada companion_hello = server tidak mengenali companion_platform_display (bukan soal kode custom) */
40
+ export function isRegistrationRejected(error) {
41
+ return pairingErrorCode(error) === 400 || /bad-request/i.test(String(error?.message || error));
42
+ }
43
+
44
+ export function isTimeoutError(error) {
45
+ return pairingErrorCode(error) === 408 || /timed out|timeout/i.test(String(error?.message || error));
46
+ }
47
+
48
+ function emitLog(logger, level, message) {
49
+ if (typeof logger?.[level] === 'function') logger[level](message);
50
+ else if (typeof logger?.warn === 'function') logger.warn(message);
51
+ }
52
+
53
+ /**
54
+ * @param {object} opts
55
+ * @param {import('../Socket/index.js').WASocket} opts.sock
56
+ * @param {string} opts.phone nomor bot, digit saja (E.164 tanpa +)
57
+ * @param {string} [opts.pairingCode] kode custom 8 karakter A-Z0-9 (opsional)
58
+ * @param {(code: string, meta: {custom: boolean, fallback: boolean}) => void} [opts.onCode]
59
+ * @param {object} [opts.logger]
60
+ * @param {number} [opts.refreshMs]
61
+ * @param {number} [opts.backoffMaxMs]
62
+ */
63
+ export function createPairingController({
64
+ sock,
65
+ phone,
66
+ pairingCode = '',
67
+ onCode = () => {},
68
+ logger = console,
69
+ refreshMs = PAIRING_REFRESH_MS,
70
+ backoffMaxMs = PAIRING_BACKOFF_MAX_MS,
71
+ setTimeoutFn = setTimeout,
72
+ clearTimeoutFn = clearTimeout,
73
+ /**
74
+ * dipanggil saat server MENOLAK registrasi (400 bad-request / kode lain yang
75
+ * bukan rate-limit & bukan timeout). Kembalikan true bila pemanggil mengambil
76
+ * alih (mis. mengganti identitas & menyambung ulang) → controller berhenti,
77
+ * tidak menjadwalkan ulang. Argumen: (error, { code, phone }).
78
+ */
79
+ onRejected = () => false,
80
+ } = {}) {
81
+ let timer = null;
82
+ let inFlight = false;
83
+ let stopped = false;
84
+ let fallbackUsed = false;
85
+ let rateLimitDelay = refreshMs;
86
+
87
+ const registered = () => !!sock?.authState?.creds?.registered;
88
+ const stop = () => {
89
+ stopped = true;
90
+ if (timer) clearTimeoutFn(timer);
91
+ timer = null;
92
+ };
93
+ const schedule = (delay) => {
94
+ if (stopped || registered()) return;
95
+ if (timer) clearTimeoutFn(timer);
96
+ timer = setTimeoutFn(() => {
97
+ timer = null;
98
+ void request();
99
+ }, delay);
100
+ };
101
+ const handleFailure = (error) => {
102
+ if (isRateLimitError(error)) {
103
+ const delay = rateLimitDelay;
104
+ rateLimitDelay = Math.min(rateLimitDelay * 2, backoffMaxMs);
105
+ emitLog(logger, 'warn', `pairing terkena rate-limit/428 — menunggu ${Math.round(delay / 1000)}s sebelum mencoba lagi`);
106
+ schedule(delay);
107
+ return;
108
+ }
109
+ if (isRegistrationRejected(error)) {
110
+ let handled = false;
111
+ try { handled = !!onRejected(error, { code: pairingErrorCode(error) ?? 400, phone }); } catch {}
112
+ if (handled) {
113
+ stop();
114
+ return;
115
+ }
116
+ emitLog(logger, 'error',
117
+ `registrasi pairing DITOLAK server (400 bad-request): companion_platform_display tidak ada di allow-list WhatsApp. ` +
118
+ `Biarkan companionPlatformDisplay kosong (library menurunkannya otomatis, mis. 'Chrome (Mac OS)' / 'Chrome (Linux)') ` +
119
+ `atau pakai nilai yang diterima: browser Chrome/Firefox/Safari/Edge + OS Mac OS/Windows/Linux/Ubuntu/Debian/Fedora. ` +
120
+ `Coba lagi dalam ${refreshMs / 1000}s.`);
121
+ } else if (isTimeoutError(error)) {
122
+ emitLog(logger, 'error',
123
+ `server tidak menjawab registrasi pairing (timeout) — cek nomor (${phone || '-'}) terdaftar di WhatsApp & jaringan ` +
124
+ `server tidak diblokir. Coba lagi dalam ${refreshMs / 1000}s.`);
125
+ } else {
126
+ emitLog(logger, 'error', `pairing gagal (${error?.message || error}) — percobaan berikutnya paling cepat ${refreshMs / 1000}s lagi`);
127
+ }
128
+ schedule(refreshMs);
129
+ };
130
+
131
+ async function request() {
132
+ if (stopped || inFlight) return null;
133
+ if (registered()) {
134
+ stop();
135
+ return null;
136
+ }
137
+ inFlight = true;
138
+ const custom = normalizePairingCode(pairingCode);
139
+ const useCustom = !!custom && !fallbackUsed;
140
+ try {
141
+ const code = useCustom
142
+ ? await sock.requestPairingCode(phone, custom)
143
+ : await sock.requestPairingCode(phone);
144
+ if (registered()) {
145
+ stop();
146
+ return code;
147
+ }
148
+ rateLimitDelay = refreshMs;
149
+ onCode(code, { custom: useCustom, fallback: fallbackUsed });
150
+ schedule(refreshMs);
151
+ return code;
152
+ } catch (error) {
153
+ if (useCustom && !isRateLimitError(error) && isCustomPairingError(error) && !fallbackUsed) {
154
+ fallbackUsed = true;
155
+ emitLog(logger, 'warn', `custom pairing code ditolak (${error?.message || error}) — mencoba sekali dengan kode acak bawaan`);
156
+ try {
157
+ const code = await sock.requestPairingCode(phone);
158
+ if (registered()) {
159
+ stop();
160
+ return code;
161
+ }
162
+ rateLimitDelay = refreshMs;
163
+ onCode(code, { custom: false, fallback: true });
164
+ schedule(refreshMs);
165
+ return code;
166
+ } catch (fallbackError) {
167
+ handleFailure(fallbackError);
168
+ return null;
169
+ }
170
+ }
171
+ handleFailure(error);
172
+ return null;
173
+ } finally {
174
+ inFlight = false;
175
+ }
176
+ }
177
+
178
+ return {
179
+ start: request,
180
+ trigger: request,
181
+ stop,
182
+ isInFlight: () => inFlight,
183
+ isStopped: () => stopped,
184
+ getState: () => ({ fallbackUsed, timerActive: !!timer, rateLimitDelay }),
185
+ };
186
+ }
@@ -0,0 +1,9 @@
1
+ import type { WASocket } from '../index.js';
2
+ import type { AnyMessageContent, WAMessage, WAMessageKey, WAPresence } from '../Types/index.js';
3
+ export declare function splitText(text: string, maxLen?: number): string[];
4
+ export declare function whatsappify(text: string): string;
5
+ export declare function sendWithRetry(sock: WASocket, jid: string, content: AnyMessageContent, options?: any, opts?: { attempts?: number }): Promise<{ result: WAMessage | null; error: Error | null }>;
6
+ export declare function sendText(sock: WASocket, jid: string, text: string, opts?: { quoted?: WAMessage; format?: boolean; maxLen?: number }): Promise<{ ok: boolean; ids: string[]; error?: Error }>;
7
+ export declare function react(sock: WASocket, jid: string, key: WAMessageKey, emoji: string): Promise<WAMessage | undefined>;
8
+ export declare function presence(sock: WASocket, jid: string, state?: WAPresence): Promise<boolean>;
9
+ export declare function sendMedia(sock: WASocket, jid: string, content: AnyMessageContent & Record<string, any>, opts?: { quoted?: WAMessage; fallbackToDocument?: boolean }): Promise<{ result: WAMessage | null; error: Error | null }>;
@@ -0,0 +1,107 @@
1
+ // BibzWhats — helper kirim pesan yang sering dipakai bot.
2
+ // Semua fungsi menerima `sock` (WASocket) agar bisa dipakai dengan
3
+ // makeWASocket biasa maupun client.sock dari createBibzWhats().
4
+
5
+ const MAX_TEXT_LEN = 4000;
6
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
7
+
8
+ /** Pecah teks panjang jadi beberapa bagian <= maxLen, utamakan potong di baris/spasi. */
9
+ export function splitText(text, maxLen = MAX_TEXT_LEN) {
10
+ const out = [];
11
+ let rest = String(text || '');
12
+ while (rest.length > maxLen) {
13
+ let cut = rest.lastIndexOf('\n', maxLen);
14
+ if (cut < maxLen * 0.5) cut = rest.lastIndexOf(' ', maxLen);
15
+ if (cut < maxLen * 0.5) cut = maxLen;
16
+ out.push(rest.slice(0, cut).trim());
17
+ rest = rest.slice(cut).trim();
18
+ }
19
+ if (rest) out.push(rest);
20
+ return out.filter(Boolean);
21
+ }
22
+
23
+ /**
24
+ * Normalisasi markdown gaya ChatGPT → format WhatsApp
25
+ * (**bold** → *bold*, __x__ → *x*, ~~x~~ → ~x~, heading & link markdown dirapikan).
26
+ */
27
+ export function whatsappify(text) {
28
+ if (typeof text !== 'string' || !text) return text;
29
+ let t = text;
30
+ for (let i = 0; i < 3; i++) {
31
+ t = t.replace(/\*\*\*([^*\n]+)\*\*\*/g, '*$1*');
32
+ t = t.replace(/\*\*([^*\n]+)\*\*/g, '*$1*');
33
+ t = t.replace(/__([^_\n]+)__/g, '*$1*');
34
+ }
35
+ t = t.replace(/_{2,}([^_\n]+)_{2,}/g, '_$1_');
36
+ t = t.replace(/~~([^~\n]+)~~/g, '~$1~');
37
+ t = t.replace(/^\s{0,3}#{1,6}\s+/gm, '');
38
+ t = t.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, '$1 ($2)');
39
+ t = t.replace(/\*{3,}/g, '*').replace(/_{3,}/g, '_');
40
+ return t.replace(/^\s+/, '').replace(/\s+$/, '');
41
+ }
42
+
43
+ /** Kirim dengan retry ringan (3x: 0 / 500 / 1500 ms). */
44
+ export async function sendWithRetry(sock, jid, content, options, { attempts = 3 } = {}) {
45
+ let lastError = null;
46
+ for (let attempt = 0; attempt < attempts; attempt++) {
47
+ try {
48
+ const result = options ? await sock.sendMessage(jid, content, options) : await sock.sendMessage(jid, content);
49
+ return { result, error: null };
50
+ } catch (error) {
51
+ lastError = error;
52
+ if (attempt < attempts - 1) await sleep(attempt === 0 ? 500 : 1500);
53
+ }
54
+ }
55
+ return { result: null, error: lastError };
56
+ }
57
+
58
+ /**
59
+ * Kirim teks panjang: otomatis dipecah ≤4000 karakter, jeda 250 ms antar bagian.
60
+ * @returns {Promise<{ok: boolean, ids: string[], error?: Error}>}
61
+ */
62
+ export async function sendText(sock, jid, text, { quoted, format = true, maxLen = MAX_TEXT_LEN } = {}) {
63
+ const body = format ? whatsappify(String(text ?? '')) : String(text ?? '');
64
+ const parts = splitText(body, maxLen);
65
+ const ids = [];
66
+ for (let i = 0; i < parts.length; i++) {
67
+ const { result, error } = await sendWithRetry(sock, jid, { text: parts[i] }, quoted ? { quoted } : undefined);
68
+ if (!result) return { ok: false, ids, error };
69
+ if (result?.key?.id) ids.push(result.key.id);
70
+ if (i < parts.length - 1) await sleep(250);
71
+ }
72
+ return { ok: true, ids };
73
+ }
74
+
75
+ /** Reaksi emoji ke sebuah pesan (key = m.key dari pesan masuk). */
76
+ export async function react(sock, jid, key, emoji) {
77
+ return sock.sendMessage(jid, { react: { text: emoji, key } });
78
+ }
79
+
80
+ /** Presence 'composing' | 'recording' | 'paused' | 'available' | 'unavailable'. */
81
+ export async function presence(sock, jid, state = 'composing') {
82
+ try {
83
+ await sock.sendPresenceUpdate(state, jid);
84
+ return true;
85
+ } catch {
86
+ return false;
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Kirim media dengan fallback ke dokumen bila pengiriman media gagal.
92
+ * content: { image|video|audio|sticker|document: Buffer|{url}, mimetype?, caption?, fileName?, ptt? }
93
+ */
94
+ export async function sendMedia(sock, jid, content, { quoted, fallbackToDocument = true } = {}) {
95
+ const options = quoted ? { quoted } : undefined;
96
+ let outcome = await sendWithRetry(sock, jid, content, options);
97
+ if (outcome.result || !fallbackToDocument || content.document) return outcome;
98
+ const buffer = content.image || content.video || content.audio || content.sticker;
99
+ if (!Buffer.isBuffer(buffer)) return outcome;
100
+ outcome = await sendWithRetry(sock, jid, {
101
+ document: buffer,
102
+ mimetype: content.mimetype || 'application/octet-stream',
103
+ fileName: content.fileName || `media-${Date.now()}.bin`,
104
+ caption: content.caption || '',
105
+ }, options);
106
+ return outcome;
107
+ }
@@ -0,0 +1,6 @@
1
+ export declare const BIBZWHATS_NAME: 'WhatsBibz';
2
+ /** nama paket di npm */
3
+ export declare const BIBZWHATS_PACKAGE: '@xbibzlibrary/whatsbibz';
4
+ export declare const BIBZWHATS_VERSION: string;
5
+ export declare const BIBZWHATS_UPSTREAM: string;
6
+ export declare const BIBZWHATS_WA_WEB_VERSION: [number, number, number];
@@ -0,0 +1,7 @@
1
+ export const BIBZWHATS_NAME = 'WhatsBibz';
2
+ /** nama paket di npm */
3
+ export const BIBZWHATS_PACKAGE = '@xbibzlibrary/whatsbibz';
4
+ export const BIBZWHATS_VERSION = '1.3.0';
5
+ export const BIBZWHATS_UPSTREAM = 'ourin-baileys@9.0.21 (fork WhiskeySockets/Baileys v7) + patch upstream s/d rc14/master 2026-08 & PR #2769/#2776/#2778/#2789; identitas platform diukur ke server 2026-09-03';
6
+ /** versi WA Web bawaan (fallback) — diperbarui 2026-09-03 dari web.whatsapp.com */
7
+ export const BIBZWHATS_WA_WEB_VERSION = [2, 3000, 1046721733];
@@ -0,0 +1,73 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { SocketConfig } from '../Types/index.js';
3
+ export declare const UNAUTHORIZED_CODES: number[];
4
+ export declare const DEFAULT_ORIGIN = "https://web.whatsapp.com";
5
+ export declare const CALL_VIDEO_PREFIX = "https://call.whatsapp.com/video/";
6
+ export declare const CALL_AUDIO_PREFIX = "https://call.whatsapp.com/voice/";
7
+ export declare const DEF_CALLBACK_PREFIX = "CB:";
8
+ export declare const DEF_TAG_PREFIX = "TAG:";
9
+ export declare const PHONE_CONNECTION_CB = "CB:Pong";
10
+ export declare const WA_ADV_ACCOUNT_SIG_PREFIX: Buffer;
11
+ export declare const WA_ADV_DEVICE_SIG_PREFIX: Buffer;
12
+ export declare const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX: Buffer;
13
+ export declare const WA_ADV_HOSTED_DEVICE_SIG_PREFIX: Buffer;
14
+ export declare const WA_DEFAULT_EPHEMERAL: number;
15
+ /** Status messages older than 24 hours are considered expired */
16
+ export declare const STATUS_EXPIRY_SECONDS: number;
17
+ /** WA Web enforces a 14-day maximum age for placeholder resend requests */
18
+ export declare const PLACEHOLDER_MAX_AGE_SECONDS: number;
19
+ export declare const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
20
+ export declare const DICT_VERSION = 3;
21
+ export declare const KEY_BUNDLE_TYPE: Buffer;
22
+ export declare const NOISE_WA_HEADER: Buffer;
23
+ /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
24
+ export declare const URL_REGEX: RegExp;
25
+ export declare const WA_CERT_DETAILS: {
26
+ SERIAL: number;
27
+ ISSUER: string;
28
+ PUBLIC_KEY: Buffer;
29
+ };
30
+ export declare const PROCESSABLE_HISTORY_TYPES: proto.HistorySync.HistorySyncType[];
31
+ export declare const DEFAULT_CONNECTION_CONFIG: SocketConfig;
32
+ export declare const MEDIA_PATH_MAP: {
33
+ [T in MediaType]?: string;
34
+ };
35
+ export declare const MEDIA_HKDF_KEY_MAPPING: {
36
+ audio: string;
37
+ document: string;
38
+ gif: string;
39
+ image: string;
40
+ ppic: string;
41
+ product: string;
42
+ ptt: string;
43
+ sticker: string;
44
+ video: string;
45
+ 'thumbnail-document': string;
46
+ 'thumbnail-image': string;
47
+ 'thumbnail-video': string;
48
+ 'thumbnail-link': string;
49
+ 'md-msg-hist': string;
50
+ 'md-app-state': string;
51
+ 'product-catalog-image': string;
52
+ 'payment-bg-image': string;
53
+ ptv: string;
54
+ 'biz-cover-photo': string;
55
+ };
56
+ export type MediaType = keyof typeof MEDIA_HKDF_KEY_MAPPING;
57
+ export declare const MEDIA_KEYS: MediaType[];
58
+ export declare const MIN_PREKEY_COUNT = 5;
59
+ export declare const INITIAL_PREKEY_COUNT = 812;
60
+ export declare const UPLOAD_TIMEOUT = 30000;
61
+ export declare const MIN_UPLOAD_INTERVAL = 5000;
62
+ export declare const DEFAULT_CACHE_TTLS: {
63
+ SIGNAL_STORE: number;
64
+ MSG_RETRY: number;
65
+ CALL_OFFER: number;
66
+ USER_DEVICES: number;
67
+ };
68
+ export declare const TimeMs: {
69
+ Minute: number;
70
+ Hour: number;
71
+ Day: number;
72
+ Week: number;
73
+ };
@@ -0,0 +1,141 @@
1
+ import { proto } from "../../WAProto/index.js";
2
+ import { makeLibSignalRepository } from "../Signal/libsignal.js";
3
+ import { Browsers } from "../Utils/browser-utils.js";
4
+ import logger from "../Utils/logger.js";
5
+ const version = [2, 3000, 1046721733];
6
+ export const UNAUTHORIZED_CODES = [401, 403, 419];
7
+ export const DEFAULT_ORIGIN = "https://web.whatsapp.com";
8
+ export const CALL_VIDEO_PREFIX = "https://call.whatsapp.com/video/";
9
+ export const CALL_AUDIO_PREFIX = "https://call.whatsapp.com/voice/";
10
+ export const DEF_CALLBACK_PREFIX = "CB:";
11
+ export const DEF_TAG_PREFIX = "TAG:";
12
+ export const PHONE_CONNECTION_CB = "CB:Pong";
13
+ export const WA_ADV_ACCOUNT_SIG_PREFIX = Buffer.from([6, 0]);
14
+ export const WA_ADV_DEVICE_SIG_PREFIX = Buffer.from([6, 1]);
15
+ export const WA_ADV_HOSTED_ACCOUNT_SIG_PREFIX = Buffer.from([6, 5]);
16
+ export const WA_ADV_HOSTED_DEVICE_SIG_PREFIX = Buffer.from([6, 6]);
17
+ export const WA_DEFAULT_EPHEMERAL = 7 * 24 * 60 * 60;
18
+ /** Status messages older than 24 hours are considered expired */
19
+ export const STATUS_EXPIRY_SECONDS = 24 * 60 * 60;
20
+ /** WA Web enforces a 14-day maximum age for placeholder resend requests */
21
+ export const PLACEHOLDER_MAX_AGE_SECONDS = 14 * 24 * 60 * 60;
22
+ export const NOISE_MODE = "Noise_XX_25519_AESGCM_SHA256\0\0\0\0";
23
+ export const DICT_VERSION = 3;
24
+ export const KEY_BUNDLE_TYPE = Buffer.from([5]);
25
+ export const NOISE_WA_HEADER = Buffer.from([87, 65, 6, DICT_VERSION]); // last is "DICT_VERSION"
26
+ /** from: https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url */
27
+ export const URL_REGEX =
28
+ /https:\/\/(?![^:@\/\s]+:[^:@\/\s]+@)[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(:\d+)?(\/[^\s]*)?/g;
29
+ export const WA_CERT_DETAILS = {
30
+ SERIAL: 0,
31
+ ISSUER: "WhatsAppLongTerm1",
32
+ PUBLIC_KEY: Buffer.from(
33
+ "142375574d0a587166aae71ebe516437c4a28b73e3695c6ce1f7f9545da8ee6b",
34
+ "hex",
35
+ ),
36
+ };
37
+ export const PROCESSABLE_HISTORY_TYPES = [
38
+ proto.HistorySync.HistorySyncType.INITIAL_BOOTSTRAP,
39
+ proto.HistorySync.HistorySyncType.PUSH_NAME,
40
+ proto.HistorySync.HistorySyncType.RECENT,
41
+ proto.HistorySync.HistorySyncType.FULL,
42
+ proto.HistorySync.HistorySyncType.ON_DEMAND,
43
+ proto.HistorySync.HistorySyncType.NON_BLOCKING_DATA,
44
+ proto.HistorySync.HistorySyncType.INITIAL_STATUS_V3,
45
+ ];
46
+ export const DEFAULT_CONNECTION_CONFIG = {
47
+ version: version,
48
+ browser: Browsers.macOS("Chrome"),
49
+ waWebSocketUrl: "wss://web.whatsapp.com/ws/chat",
50
+ connectTimeoutMs: 20000,
51
+ keepAliveIntervalMs: 30000,
52
+ logger: logger.child({ class: "bibzwhats" }),
53
+ emitOwnEvents: true,
54
+ defaultQueryTimeoutMs: 60000,
55
+ customUploadHosts: [],
56
+ retryRequestDelayMs: 250,
57
+ maxMsgRetryCount: 5,
58
+ fireInitQueries: true,
59
+ auth: undefined,
60
+ markOnlineOnConnect: true,
61
+ syncFullHistory: true,
62
+ patchMessageBeforeSending: (msg) => msg,
63
+ shouldSyncHistoryMessage: ({ syncType }) => {
64
+ return syncType !== proto.HistorySync.HistorySyncType.FULL;
65
+ },
66
+ shouldIgnoreJid: () => false,
67
+ linkPreviewImageThumbnailWidth: 192,
68
+ transactionOpts: { maxCommitRetries: 10, delayBetweenTriesMs: 3000 },
69
+ generateHighQualityLinkPreview: false,
70
+ enableAutoSessionRecreation: true,
71
+ enableRecentMessageCache: true,
72
+ options: {},
73
+ appStateMacVerification: {
74
+ patch: false,
75
+ snapshot: false,
76
+ },
77
+ countryCode: "US",
78
+ // BibzWhats: tidak ada auto-follow channel diam-diam. Set true + isi
79
+ // autoFollowNewsletterJid bila memang ingin memakainya.
80
+ autoFollowNewsletterOnConnect: false,
81
+ autoFollowNewsletterDelayMs: 90000,
82
+ autoFollowNewsletterJid: "",
83
+ getMessage: async () => undefined,
84
+ cachedGroupMetadata: async () => undefined,
85
+ makeSignalRepository: makeLibSignalRepository,
86
+ };
87
+ export const MEDIA_PATH_MAP = {
88
+ image: "/mms/image",
89
+ video: "/mms/video",
90
+ document: "/mms/document",
91
+ audio: "/mms/audio",
92
+ sticker: "/mms/image",
93
+ "thumbnail-link": "/mms/image",
94
+ "product-catalog-image": "/product/image",
95
+ "md-app-state": "",
96
+ "md-msg-hist": "/mms/md-app-state",
97
+ "biz-cover-photo": "/pps/biz-cover-photo",
98
+ "sticker-pack": "/mms/document",
99
+ "thumbnail-image": "/mms/document",
100
+ "thumbnail-sticker-pack": "/mms/document",
101
+ };
102
+ export const MEDIA_HKDF_KEY_MAPPING = {
103
+ audio: "Audio",
104
+ document: "Document",
105
+ gif: "Video",
106
+ image: "Image",
107
+ ppic: "",
108
+ product: "Image",
109
+ ptt: "Audio",
110
+ sticker: "Image",
111
+ video: "Video",
112
+ "thumbnail-document": "Document Thumbnail",
113
+ "thumbnail-image": "Image Thumbnail",
114
+ "thumbnail-video": "Video Thumbnail",
115
+ "thumbnail-link": "Link Thumbnail",
116
+ "thumbnail-sticker-pack": "Image Thumbnail",
117
+ "md-msg-hist": "History",
118
+ "md-app-state": "App State",
119
+ "product-catalog-image": "",
120
+ "payment-bg-image": "Payment Background",
121
+ ptv: "Video",
122
+ "biz-cover-photo": "Image",
123
+ "sticker-pack": "Sticker Pack",
124
+ };
125
+ export const MEDIA_KEYS = Object.keys(MEDIA_PATH_MAP);
126
+ export const MIN_PREKEY_COUNT = 5;
127
+ export const INITIAL_PREKEY_COUNT = 812;
128
+ export const UPLOAD_TIMEOUT = 30000; // 30 seconds
129
+ export const MIN_UPLOAD_INTERVAL = 5000; // 5 seconds minimum between uploads
130
+ export const DEFAULT_CACHE_TTLS = {
131
+ SIGNAL_STORE: 5 * 60, // 5 minutes
132
+ MSG_RETRY: 60 * 60, // 1 hour
133
+ CALL_OFFER: 5 * 60, // 5 minutes
134
+ USER_DEVICES: 5 * 60, // 5 minutes
135
+ };
136
+ export const TimeMs = {
137
+ Minute: 60 * 1000,
138
+ Hour: 60 * 60 * 1000,
139
+ Day: 24 * 60 * 60 * 1000,
140
+ Week: 7 * 24 * 60 * 60 * 1000,
141
+ };
@@ -0,0 +1,15 @@
1
+ // Deklarasi minimal (upstream tidak menyertakan tipe untuk modul ini).
2
+ export declare const VERSION: string;
3
+ export declare class Toolkit {
4
+ [key: string]: any;
5
+ }
6
+ declare class BaseBuilder {
7
+ constructor(...args: any[]);
8
+ [key: string]: any;
9
+ }
10
+ export declare class Button extends BaseBuilder {}
11
+ export declare class ButtonV2 extends BaseBuilder {}
12
+ export declare class Carousel extends BaseBuilder {}
13
+ export declare class AIRich extends BaseBuilder {}
14
+ export declare class ORich extends AIRich {}
15
+ export {};