@oxidezap/baileyrs 0.3.1 → 0.3.3

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.
package/README.md CHANGED
@@ -237,6 +237,18 @@ preserved. No QR re-scan, no logged-out events.
237
237
 
238
238
  A few behaviors that differ from upstream — almost always to your advantage:
239
239
 
240
+ - **An undecryptable message tells you what it was.** The CIPHERTEXT stub
241
+ emitted on `messages.upsert` for a message that failed to decrypt carries
242
+ `stanzaType`: the envelope's `type` attribute as the server stamped it on the
243
+ sending stanza — `"text"`, `"media"`, `"pay"`, `"poll"`, `"reaction"`,
244
+ `"event"`. It describes the stanza rather than the ciphertext, so it survives
245
+ the failure, and it is stamped on the sender's own outgoing stanza, so it
246
+ cannot be pointed at anyone else. Upstream has no equivalent: there the
247
+ placeholder is unclassifiable. `messageStubParameters` is untouched and still
248
+ holds only the unavailability reason, when the server named one — the two are
249
+ independently optional, which is exactly what a positional array cannot
250
+ express.
251
+
240
252
  - **Auto-reconnect is built in, but `close` still means `close`.** The Rust
241
253
  engine retries transient drops on a fibonacci backoff and reports them as
242
254
  `connection: 'connecting'`, so the canonical upstream handler never fires
@@ -297,6 +309,11 @@ A few behaviors that differ from upstream — almost always to your advantage:
297
309
  `(err as Boom).output.statusCode` pattern works unchanged. If your
298
310
  `package.json` was pulling `@hapi/boom` only for baileys, you can drop
299
311
  the dependency.
312
+ - **Audio duration needs the optional `music-metadata` peer.** Upstream
313
+ Baileys bundles it as a hard dependency; here it is optional like the
314
+ other media peers (`sharp`, `jimp`, `audio-decode`, `link-preview-js`).
315
+ Without it, audio messages still send — they just carry no `seconds`
316
+ value. Install `music-metadata` if you want durations computed.
300
317
  - **Your key store also holds bridge state, so "empty" is not "unpaired".**
301
318
  See [Bridge state in your key store](#bridge-state-in-your-key-store) — this
302
319
  one can break a boot path, so it has its own section.
@@ -190,6 +190,7 @@ const ADAPTERS = {
190
190
  remoteJidAlt: resolveRemoteJidAlt(senderAlt, recipientAlt, isGroup, isFromMe),
191
191
  isUnavailable: asBoolOr(data?.is_unavailable, false),
192
192
  unavailableType: asString(data?.unavailable_type),
193
+ stanzaType: asString(info.type),
193
194
  decryptFailMode: asString(data?.decrypt_fail_mode),
194
195
  raw: data
195
196
  };
@@ -566,6 +566,13 @@ export interface CanonicalUndecryptableMessage {
566
566
  isUnavailable: boolean;
567
567
  /** Bridge `unavailable_type`: "view_once" | "unknown". */
568
568
  unavailableType?: string;
569
+ /**
570
+ * The envelope's `type` attribute, as the server stamped it: "text",
571
+ * "media", "pay", "poll", "reaction", "event"… It describes the stanza,
572
+ * not the ciphertext, so it survives a decryption failure — the one thing
573
+ * a consumer can still learn about a message it cannot read.
574
+ */
575
+ stanzaType?: string;
569
576
  /** Bridge `decrypt_fail_mode`: "show" | "hide". */
570
577
  decryptFailMode?: string;
571
578
  /** Original raw payload, preserved for debug logging. */
@@ -532,9 +532,9 @@ class ProtoCompatibilityRuntime {
532
532
  return appendBytes(writer, finish());
533
533
  // The codec's own writer is what comes back, with `finish` shadowed on
534
534
  // the instance rather than replaced by a bare `{ finish }`. The published
535
- // declaration types this return as a protobufjs `Writer`, and a caller
536
- // that chains anything on it — `fork`, `join`, another field — has to
537
- // find the rest of the surface still there. The writer is freshly made
535
+ // declaration types this return as the facade's structural `Writer`,
536
+ // which mirrors the `protobufjs` 7.6.6 instance surface Baileys
537
+ // consumers hold, so a caller chaining on it keeps typechecking. The writer is freshly made
538
538
  // by this call, so shadowing one method on it touches nothing else.
539
539
  encoded.finish = finish;
540
540
  return encoded;
@@ -479,6 +479,15 @@ const DISPATCHERS = {
479
479
  stubMsg.key.participantAlt = evt.participantAlt;
480
480
  if (evt.remoteJidAlt)
481
481
  stubMsg.key.remoteJidAlt = evt.remoteJidAlt;
482
+ // A field of its own, not a second slot in `messageStubParameters`:
483
+ // that array is positional, and two independently optional values in it
484
+ // cannot be told apart — a lone `"pay"` would sit where an
485
+ // unavailability reason used to. This is the one thing that survives a
486
+ // decryption failure to say what the message was (the server stamps it
487
+ // on the sender's own outgoing stanza, in the clear), so it is named
488
+ // rather than placed.
489
+ if (evt.stanzaType)
490
+ stubMsg.stanzaType = evt.stanzaType;
482
491
  ctx.ev.emit('messages.upsert', { messages: [stubMsg], type: 'notify' });
483
492
  },
484
493
  // ── Contacts ──
@@ -29,6 +29,15 @@ export type WAMessage = Omit<proto.IWebMessageInfo, 'messageStubParameters' | 'm
29
29
  category?: string;
30
30
  retryCount?: number;
31
31
  messageStubParameters?: any;
32
+ /**
33
+ * The envelope's `type` attribute, as the server stamped it on the sending
34
+ * stanza: `"text"`, `"media"`, `"pay"`, `"poll"`, `"reaction"`, `"event"`.
35
+ *
36
+ * Set only on the CIPHERTEXT stub emitted for a message that failed to
37
+ * decrypt, where it is the one fact about the message that survives — it
38
+ * describes the stanza, not the ciphertext. Absent everywhere else.
39
+ */
40
+ stanzaType?: string;
32
41
  };
33
42
  export type WAMessageContent = proto.IMessage;
34
43
  export type WAContactMessage = proto.Message.IContactMessage;
@@ -1,3 +1,11 @@
1
+ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
2
+ if (typeof path === "string" && /^\.\.?\//.test(path)) {
3
+ return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
4
+ return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
5
+ });
6
+ }
7
+ return path;
8
+ };
1
9
  import { Buffer } from 'node:buffer';
2
10
  import { execFile } from 'node:child_process';
3
11
  import { randomBytes } from 'node:crypto';
@@ -113,7 +121,19 @@ export const mediaMessageSHA256B64 = (message) => {
113
121
  };
114
122
  /** Returns audio duration in seconds, parsed via `music-metadata`. */
115
123
  export async function getAudioDuration(buffer) {
116
- const musicMetadata = await import('music-metadata');
124
+ // `music-metadata` is an optional peer: without it the duration is simply
125
+ // unknown and the caller sends without `seconds`. The specifier cast keeps
126
+ // bundlers from failing the build when the peer is absent, the same trick
127
+ // `link-preview.ts` uses for `link-preview-js`. Only the import is
128
+ // guarded: parser failures still throw so the caller's warning reports
129
+ // corrupt audio instead of silently dropping the duration.
130
+ let musicMetadata;
131
+ try {
132
+ musicMetadata = await import(__rewriteRelativeImportExtension('music-metadata'));
133
+ }
134
+ catch {
135
+ return undefined;
136
+ }
117
137
  let metadata;
118
138
  const options = {
119
139
  duration: true
@@ -1,6 +1,69 @@
1
1
  // Generated by scripts/compatibility/waproto-facade.ts. Do not edit.
2
2
  // Type-only Baileys compatibility facade; runtime codecs remain whatsapp-rust-bridge.
3
- import * as $protobuf from "protobufjs";
3
+ declare namespace $protobuf {
4
+ interface Long {
5
+ low: number;
6
+ high: number;
7
+ unsigned: boolean;
8
+ }
9
+ interface Writer {
10
+ len: number;
11
+ head: object;
12
+ tail: object;
13
+ states: (object|null);
14
+ uint32(value: number): Writer;
15
+ int32(value: number): Writer;
16
+ sint32(value: number): Writer;
17
+ uint64(value: (Long|number|string)): Writer;
18
+ int64(value: (Long|number|string)): Writer;
19
+ sint64(value: (Long|number|string)): Writer;
20
+ bool(value: boolean): Writer;
21
+ fixed32(value: number): Writer;
22
+ sfixed32(value: number): Writer;
23
+ fixed64(value: (Long|number|string)): Writer;
24
+ sfixed64(value: (Long|number|string)): Writer;
25
+ float(value: number): Writer;
26
+ double(value: number): Writer;
27
+ bytes(value: (Uint8Array|string)): Writer;
28
+ string(value: string): Writer;
29
+ fork(): Writer;
30
+ reset(): Writer;
31
+ ldelim(): Writer;
32
+ finish(): Uint8Array;
33
+ }
34
+ interface Reader {
35
+ buf: Uint8Array;
36
+ pos: number;
37
+ len: number;
38
+ uint32(): number;
39
+ int32(): number;
40
+ sint32(): number;
41
+ int64(): Long;
42
+ uint64(): Long;
43
+ sint64(): Long;
44
+ bool(): boolean;
45
+ fixed32(): number;
46
+ sfixed32(): number;
47
+ fixed64(): Long;
48
+ sfixed64(): Long;
49
+ float(): number;
50
+ double(): number;
51
+ bytes(): Uint8Array;
52
+ string(): string;
53
+ skip(length?: number): Reader;
54
+ skipType(wireType: number, depth?: number): Reader;
55
+ }
56
+ interface IConversionOptions {
57
+ longs?: Function;
58
+ enums?: Function;
59
+ bytes?: Function;
60
+ defaults?: boolean;
61
+ arrays?: boolean;
62
+ objects?: boolean;
63
+ oneofs?: boolean;
64
+ json?: boolean;
65
+ }
66
+ }
4
67
  import Long = require("long");
5
68
  export namespace proto {
6
69
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oxidezap/baileyrs",
3
3
  "type": "module",
4
- "version": "0.3.1",
4
+ "version": "0.3.3",
5
5
  "description": "A Rust-powered WhatsApp Web library for JavaScript, with a Baileys-compatible API",
6
6
  "keywords": [
7
7
  "whatsapp",
@@ -83,10 +83,9 @@
83
83
  },
84
84
  "dependencies": {
85
85
  "@hapi/boom": "^10.0.1",
86
- "@oxidezap/whatsapp-rust-bridge": "0.21.2",
86
+ "@oxidezap/whatsapp-rust-bridge": "0.21.4",
87
87
  "long": "^5.3.2",
88
- "pino": "^10.3.1",
89
- "protobufjs": "^8.8.0"
88
+ "pino": "^10.3.1"
90
89
  },
91
90
  "devDependencies": {
92
91
  "@bufbuild/protobuf": "^2.13.0",
@@ -99,6 +98,7 @@
99
98
  "oxlint": "1.81.0",
100
99
  "pino-pretty": "^13.1.3",
101
100
  "pkg-pr-new": "^0.0.88",
101
+ "protobufjs": "^8.8.0",
102
102
  "tsc-esm-fix": "^3.1.2",
103
103
  "typescript": "^7.0.2",
104
104
  "typescript-compat-auditor": "npm:typescript@6.0.3"
@@ -107,6 +107,7 @@
107
107
  "audio-decode": "^2.1.3",
108
108
  "jimp": "^1.6.0",
109
109
  "link-preview-js": "^3.0.0",
110
+ "music-metadata": "^11.14.0",
110
111
  "sharp": "*"
111
112
  },
112
113
  "peerDependenciesMeta": {
@@ -119,13 +120,13 @@
119
120
  "link-preview-js": {
120
121
  "optional": true
121
122
  },
123
+ "music-metadata": {
124
+ "optional": true
125
+ },
122
126
  "sharp": {
123
127
  "optional": true
124
128
  }
125
129
  },
126
- "overrides": {
127
- "protobufjs": "^8.8.0"
128
- },
129
130
  "publishConfig": {
130
131
  "access": "public"
131
132
  },