@oxidezap/baileyrs 0.3.7 → 0.3.9

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 (129) hide show
  1. package/README.md +56 -8
  2. package/lib/Bridge/history-sync-wire.d.ts +2 -2
  3. package/lib/Bridge/history-sync-wire.js +4 -4
  4. package/lib/Bridge/schema.js +7 -1
  5. package/lib/Bridge/types.d.ts +7 -1
  6. package/lib/Compatibility/auth-state.d.ts +30 -0
  7. package/lib/Compatibility/auth-state.js +96 -0
  8. package/lib/Compatibility/encode-proto-core.d.ts +31 -0
  9. package/lib/Compatibility/encode-proto-core.js +51 -0
  10. package/lib/Compatibility/encode-proto.d.ts +0 -29
  11. package/lib/Compatibility/encode-proto.js +3 -50
  12. package/lib/Compatibility/host-auth-state.d.ts +6 -0
  13. package/lib/Compatibility/host-auth-state.js +162 -0
  14. package/lib/Compatibility/internal/auth-state.d.ts +3 -7
  15. package/lib/Compatibility/internal/auth-state.js +34 -1
  16. package/lib/Compatibility/internal/host-auth-state.d.ts +4 -0
  17. package/lib/Compatibility/internal/host-auth-state.js +14 -0
  18. package/lib/Compatibility/legacy-store/device.js +5 -5
  19. package/lib/Compatibility/message-ids.d.ts +17 -0
  20. package/lib/Compatibility/message-ids.js +47 -0
  21. package/lib/Compatibility/message-relay.d.ts +2 -2
  22. package/lib/Compatibility/message-relay.js +4 -4
  23. package/lib/Compatibility/proto-runtime.js +33 -11
  24. package/lib/Compatibility/socket-results.d.ts +1 -1
  25. package/lib/Compatibility/tagged-message-waiter.d.ts +5 -2
  26. package/lib/Compatibility/tagged-message-waiter.js +5 -5
  27. package/lib/Compatibility/usync/adapter.d.ts +1 -1
  28. package/lib/Compatibility/websocket-client.d.ts +11 -3
  29. package/lib/Compatibility/websocket-client.js +84 -11
  30. package/lib/Defaults/index.d.ts +8 -8
  31. package/lib/Defaults/index.js +8 -8
  32. package/lib/Media/content.d.ts +28 -0
  33. package/lib/Media/content.js +129 -0
  34. package/lib/Media/core.d.ts +34 -0
  35. package/lib/Media/core.js +120 -0
  36. package/lib/Media/mutations.d.ts +24 -0
  37. package/lib/Media/mutations.js +38 -0
  38. package/lib/Runtime/aes-gcm.d.ts +4 -0
  39. package/lib/Runtime/aes-gcm.js +11 -0
  40. package/lib/Runtime/bridge.d.ts +44 -0
  41. package/lib/Runtime/bridge.js +76 -0
  42. package/lib/Runtime/buffer.d.ts +9 -0
  43. package/lib/Runtime/buffer.js +22 -0
  44. package/lib/Runtime/bytes.d.ts +61 -0
  45. package/lib/Runtime/bytes.js +270 -0
  46. package/lib/Runtime/host.d.ts +22 -0
  47. package/lib/Runtime/host.js +43 -0
  48. package/lib/Runtime/long.d.ts +33 -0
  49. package/lib/Runtime/long.js +64 -0
  50. package/lib/Runtime/node-media-processors.d.ts +4 -0
  51. package/lib/Runtime/node-media-processors.js +29 -0
  52. package/lib/Runtime/node-media.d.ts +28 -0
  53. package/lib/Runtime/node-media.js +115 -0
  54. package/lib/Runtime/node.d.ts +14 -0
  55. package/lib/Runtime/node.js +81 -0
  56. package/lib/Runtime/paths.d.ts +4 -0
  57. package/lib/Runtime/paths.js +7 -0
  58. package/lib/Runtime/stream.d.ts +11 -0
  59. package/lib/Runtime/stream.js +25 -0
  60. package/lib/Runtime/types.d.ts +98 -0
  61. package/lib/Runtime/types.js +13 -0
  62. package/lib/Socket/core.d.ts +312 -0
  63. package/lib/Socket/core.js +1134 -0
  64. package/lib/Socket/events-core.d.ts +75 -0
  65. package/lib/Socket/events-core.js +1058 -0
  66. package/lib/Socket/events.d.ts +1 -63
  67. package/lib/Socket/events.js +4 -1047
  68. package/lib/Socket/groups.js +4 -3
  69. package/lib/Socket/index.d.ts +521 -103
  70. package/lib/Socket/index.js +10 -1007
  71. package/lib/Socket/messages-core.d.ts +41 -0
  72. package/lib/Socket/messages-core.js +270 -0
  73. package/lib/Socket/messages.d.ts +9 -36
  74. package/lib/Socket/messages.js +3 -260
  75. package/lib/Socket/newsletter.js +3 -3
  76. package/lib/Socket/profile.js +1 -1
  77. package/lib/Socket/terminal-close-reporter.d.ts +2 -0
  78. package/lib/Socket/terminal-close-reporter.js +3 -3
  79. package/lib/Socket/transport.d.ts +2 -0
  80. package/lib/Socket/transport.js +16 -1
  81. package/lib/Socket/types.d.ts +2 -0
  82. package/lib/Types/Auth.d.ts +11 -0
  83. package/lib/Types/Message.d.ts +1 -1
  84. package/lib/Types/Socket.d.ts +2 -2
  85. package/lib/Types/index.d.ts +6 -1
  86. package/lib/Utils/browser-utils.d.ts +4 -0
  87. package/lib/Utils/browser-utils.js +53 -2
  88. package/lib/Utils/crypto.d.ts +1 -0
  89. package/lib/Utils/crypto.js +1 -0
  90. package/lib/Utils/event-buffer.d.ts +6 -1
  91. package/lib/Utils/event-buffer.js +28 -27
  92. package/lib/Utils/link-preview.d.ts +4 -3
  93. package/lib/Utils/logger.d.ts +3 -0
  94. package/lib/Utils/logger.js +35 -6
  95. package/lib/Utils/messages-core.d.ts +174 -0
  96. package/lib/Utils/messages-core.js +1042 -0
  97. package/lib/Utils/messages-media-core.d.ts +73 -0
  98. package/lib/Utils/messages-media-core.js +319 -0
  99. package/lib/Utils/messages-media.d.ts +1 -72
  100. package/lib/Utils/messages-media.js +9 -358
  101. package/lib/Utils/messages.d.ts +1 -166
  102. package/lib/Utils/messages.js +7 -1040
  103. package/lib/Utils/optional-peer.js +14 -5
  104. package/lib/Utils/process-history-message-core.d.ts +36 -0
  105. package/lib/Utils/process-history-message-core.js +187 -0
  106. package/lib/Utils/process-history-message.d.ts +5 -43
  107. package/lib/Utils/process-history-message.js +11 -197
  108. package/lib/Utils/process-message-core.d.ts +29 -0
  109. package/lib/Utils/process-message-core.js +112 -0
  110. package/lib/Utils/process-message.d.ts +4 -24
  111. package/lib/Utils/process-message.js +6 -111
  112. package/lib/WABinary/generic-utils.js +7 -5
  113. package/lib/host-shared.d.ts +74 -0
  114. package/lib/host-shared.js +15 -0
  115. package/lib/host-socket-operations.d.ts +3 -0
  116. package/lib/host-socket-operations.js +2 -0
  117. package/lib/host-surface.d.ts +21 -0
  118. package/lib/host-surface.js +35 -0
  119. package/lib/host-types.d.ts +356 -0
  120. package/lib/host-types.js +2 -0
  121. package/lib/host.d.ts +33 -0
  122. package/lib/host.js +31 -0
  123. package/lib/node-surface.d.ts +9 -0
  124. package/lib/node-surface.js +15 -0
  125. package/lib/surface.d.ts +5 -0
  126. package/lib/surface.js +6 -0
  127. package/lib/wasm.d.ts +27 -0
  128. package/lib/wasm.js +27 -0
  129. package/package.json +18 -6
@@ -0,0 +1,174 @@
1
+ import type { Buffer } from 'node:buffer';
2
+ import LongRuntime from 'long';
3
+ import type { Readable } from 'node:stream';
4
+ import type { WasmWhatsAppClient } from '@oxidezap/whatsapp-rust-bridge';
5
+ import { type MediaType } from '../Defaults/index.js';
6
+ import type { AnyMediaMessageContent, AnyMessageContent, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAMessageKey } from '../Types/index.js';
7
+ import { WAProto } from '../Types/index.js';
8
+ import { proto } from '../WAProto/runtime.js';
9
+ import type { ILogger } from './logger.js';
10
+ import { type MediaDownloadOptions } from './messages-media-core.js';
11
+ type ExtractByKey<T, K extends PropertyKey> = T extends Record<K, unknown> ? T : never;
12
+ /**
13
+ * Uses a regex to test whether the string contains a URL, and returns the URL if it does.
14
+ * @param text eg. hello https://google.com
15
+ * @returns the URL, eg. https://google.com
16
+ */
17
+ export declare const extractUrlFromText: (text: string) => string | undefined;
18
+ export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions['getUrlInfo'], logger: MessageGenerationOptions['logger']) => Promise<import("../index.js").WAUrlInfo | undefined>;
19
+ export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MessageContentGenerationOptions) => Promise<WAProto.Message>;
20
+ export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number) => WAProto.Message;
21
+ /**
22
+ * Generate forwarded message content like WA does
23
+ * @param message the message to forward
24
+ * @param options.forceForward will show the message as forwarded even if it is from you
25
+ */
26
+ export declare const generateForwardMessageContent: (message: WAMessage, forceForward?: boolean) => WAProto.IMessage;
27
+ export declare const hasNonNullishProperty: <K extends PropertyKey>(message: AnyMessageContent, key: K) => message is ExtractByKey<AnyMessageContent, K>;
28
+ type RuntimeRandomOptions = {
29
+ runtimeRandomBytes?: (length: number) => Uint8Array;
30
+ };
31
+ type RuntimeLongOptions = {
32
+ runtimeLong?: Pick<typeof LongRuntime, 'fromValue'>;
33
+ };
34
+ export declare const generateWAMessageContent: (message: AnyMessageContent, options: MessageContentGenerationOptions & RuntimeRandomOptions) => Promise<WAProto.Message>;
35
+ export declare const generateWAMessageFromContent: (jid: string, message: WAMessageContent, options: MessageGenerationOptionsFromContent & RuntimeLongOptions) => WAMessage;
36
+ export declare const generateWAMessage: (jid: string, content: AnyMessageContent, options: MessageGenerationOptions & RuntimeRandomOptions & RuntimeLongOptions) => Promise<WAMessage>;
37
+ /** Get the key to access the true type of content */
38
+ export declare const getContentType: (content: proto.IMessage | undefined) => keyof WAProto.IMessage | undefined;
39
+ /**
40
+ * Normalizes ephemeral, view once messages to regular message content
41
+ * Eg. image messages in ephemeral messages, in view once messages etc.
42
+ * @param content
43
+ * @returns
44
+ */
45
+ export declare const normalizeMessageContent: (content: WAMessageContent | null | undefined) => WAMessageContent | undefined;
46
+ /**
47
+ * Extract the true message content from a message
48
+ * Eg. extracts the inner message from a disappearing message/view once message
49
+ */
50
+ export declare const extractMessageContent: (content: WAMessageContent | undefined | null) => WAMessageContent | undefined;
51
+ /**
52
+ * Every field is optional, so upstream's `{ reuploadRequest, logger }` and this
53
+ * package's `{ waClient }` are both accepted.
54
+ *
55
+ * `reuploadRequest` and `logger` are declared for that compatibility and are
56
+ * not read: the engine handles the re-upload request, the CDN failover and the
57
+ * logging itself, so a caller's versions would have nothing to do.
58
+ */
59
+ export type DownloadMediaMessageContext = {
60
+ reuploadRequest?: (msg: WAMessage) => Promise<WAMessage>;
61
+ logger?: ILogger;
62
+ /** Bridge client for media download. Falls back to the registered one. */
63
+ waClient?: Pick<WasmWhatsAppClient, 'downloadMedia' | 'downloadMediaStream'>;
64
+ };
65
+ export declare const MEDIA_DOWNLOAD_TYPES: readonly ['buffer', 'stream'];
66
+ export type MediaDownloadType = (typeof MEDIA_DOWNLOAD_TYPES)[number];
67
+ /**
68
+ * Downloads the given message. Throws an error if it's not a media message.
69
+ *
70
+ * Uses the Rust bridge for download — provides CDN failover, automatic auth
71
+ * refresh on 401/404, HMAC-SHA256 integrity verification, and AES-256-CBC
72
+ * decryption, so a bridge client has to reach it.
73
+ *
74
+ * `ctx` is optional, as upstream has it: without one the client registered by
75
+ * the most recent `makeWASocket` is used, the same fallback
76
+ * `downloadContentFromMessage` offers for standalone calls. A host juggling
77
+ * several sockets should pass `ctx` explicitly, because the registration points
78
+ * at whichever client was created last.
79
+ */
80
+ export declare const downloadMediaMessage: <Type extends MediaDownloadType>(message: WAMessage, type: Type, options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext) => Promise<Type extends "buffer" ? Buffer<ArrayBufferLike> : Readable>;
81
+ export declare const _registerActiveBridgeClient: (client: WasmWhatsAppClient, logger?: ILogger) => void;
82
+ /**
83
+ * Drop the module-level pointer when `sock.end()` frees the client it points
84
+ * at. Without this the global keeps a strong reference to a freed
85
+ * `WasmWhatsAppClient`, so the next standalone `downloadContentFromMessage()`
86
+ * call reaches into a null wasm pointer and fails with an opaque
87
+ * wasm-bindgen error instead of the actionable "no bridge client" Boom.
88
+ *
89
+ * Identity-checked on purpose: a multi-account host that ends socket A after
90
+ * creating socket B must not clear B's registration.
91
+ */
92
+ export declare const _unregisterActiveBridgeClient: (client: WasmWhatsAppClient) => void;
93
+ /**
94
+ * Upstream-Baileys-compatible standalone media download. Builds a synthetic
95
+ * `WAMessage` from the supplied media subcontent (image/video/audio/etc fields)
96
+ * and routes it through {@link downloadMediaMessage}, so CDN failover, auth
97
+ * refresh, HMAC verification, and AES-256-CBC decryption all happen inside the
98
+ * Rust bridge — same code path as `sock.downloadMedia`.
99
+ *
100
+ * The bridge client is required. Pass it explicitly via `opts.client` for
101
+ * multi-account hosts; otherwise the helper falls back to the most-recently
102
+ * created bridge client (registered automatically by `makeWASocket`).
103
+ */
104
+ export declare const downloadContentFromMessage: (mediaContent: {
105
+ directPath?: string | null;
106
+ mediaKey?: Uint8Array | null;
107
+ fileSha256?: Uint8Array | null;
108
+ fileEncSha256?: Uint8Array | null;
109
+ fileLength?: number | Long | null;
110
+ url?: string | null;
111
+ }, type: MediaType, opts?: MediaDownloadOptions & {
112
+ client?: WasmWhatsAppClient;
113
+ logger?: ILogger;
114
+ }) => Promise<Readable>;
115
+ type Long = {
116
+ low: number;
117
+ high: number;
118
+ unsigned: boolean;
119
+ };
120
+ type VoteAggregation = {
121
+ name: string;
122
+ voters: string[];
123
+ };
124
+ type ResponseAggregation = {
125
+ response: string;
126
+ responders: string[];
127
+ };
128
+ /** Infer the originating client family from WhatsApp's message-id format. */
129
+ export declare const getDevice: (id: string) => "android" | "desktop" | "ios" | "unknown" | "web";
130
+ /**
131
+ * Aggregate votes from a poll message.
132
+ *
133
+ * Takes a poll creation message and its accumulated poll updates (from
134
+ * `messages.update` events) and returns the vote tally per option.
135
+ *
136
+ * `pollUpdates` should contain pre-decrypted votes where `vote.selectedOptions`
137
+ * are the SHA-256 hashes of the voted option names.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * sock.ev.on('messages.update', event => {
142
+ * for (const { key, update } of event) {
143
+ * if (update.pollUpdates) {
144
+ * const pollMsg = await getMessageFromStore(key)
145
+ * const votes = getAggregateVotesInPollMessage({
146
+ * message: pollMsg.message,
147
+ * pollUpdates: pollMsg.pollUpdates
148
+ * })
149
+ * console.log(votes) // [{ name: 'Yes', voters: ['jid1'] }, ...]
150
+ * }
151
+ * }
152
+ * })
153
+ * ```
154
+ */
155
+ export declare function getAggregateVotesInPollMessage({ message, pollUpdates }: Pick<WAMessage, 'pollUpdates' | 'message'>, meId?: string): VoteAggregation[];
156
+ export declare function getAggregateResponsesInEventMessage({ eventResponses }: Pick<WAMessage, 'eventResponses'>, meId?: string): ResponseAggregation[];
157
+ /** Group non-self message keys by chat and participant for bulk receipts. */
158
+ export declare const aggregateMessageKeysNotFromMe: (keys: WAMessageKey[]) => {
159
+ jid: string;
160
+ participant: string | undefined;
161
+ messageIds: string[];
162
+ }[];
163
+ /** Upsert one receipt into a message's `userReceipt` collection. */
164
+ export declare const updateMessageWithReceipt: (msg: Pick<WAMessage, 'userReceipt'>, receipt: MessageUserReceipt) => void;
165
+ /** Replace the previous reaction from the same author, then append the latest. */
166
+ export declare const updateMessageWithReaction: (msg: Pick<WAMessage, 'reactions'>, reaction: proto.IReaction) => void;
167
+ /** Replace the previous poll update from the same author. Empty votes remove it. */
168
+ export declare const updateMessageWithPollUpdate: (msg: Pick<WAMessage, 'pollUpdates'>, update: proto.IPollUpdate) => void;
169
+ /** Replace the previous event response from the same author. */
170
+ export declare const updateMessageWithEventResponse: (msg: Pick<WAMessage, 'eventResponses'>, update: proto.IEventResponse) => void;
171
+ /** Checks whether the message contains one of the upstream media payloads. */
172
+ export declare const assertMediaContent: (content: proto.IMessage | null | undefined) => WAProto.Message.IAudioMessage | WAProto.Message.IDocumentMessage | WAProto.Message.IImageMessage | WAProto.Message.IStickerMessage | WAProto.Message.IVideoMessage;
173
+ export {};
174
+ //# sourceMappingURL=messages-core.d.ts.map