@oxidezap/whatsapp-rust-bridge 0.16.0 → 0.18.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.
@@ -1064,6 +1064,7 @@ export interface MsgBotInfo {
1064
1064
  edit_sender_timestamp_ms?: string | null;
1065
1065
  }
1066
1066
 
1067
+ /** The short `<meta>` attributes are `CompactString`: a message id is 22 wire characters and the rest are short keywords ("add_on", "default"), so all of them live in the 24 inline bytes and parsing a `<meta>` child allocates nothing for them. */
1067
1068
  export interface MsgMetaInfo {
1068
1069
  target_id?: string | null;
1069
1070
  target_sender?: Jid | null;
@@ -2655,7 +2656,7 @@ export type PresenceStatus = "available" | "unavailable";
2655
2656
  * `From` impls below by walking the source chain. This keeps the JS object
2656
2657
  * shape predictable and the codegen / `Tsify` output simple.
2657
2658
  */
2658
- export type BridgeError = { kind: "server"; serverCode: number; serverText: string; errorType?: string; backoffSeconds?: number } | { kind: "timeout" } | { kind: "not-connected" } | { kind: "disconnected"; reason: string } | { kind: "invalid-argument"; field: string; reason: string } | { kind: "protocol-violation"; reason: string } | { kind: "crypto"; operation: string } | { kind: "storage"; operation: string } | { kind: "no-recipient-device"; attempted: number } | { kind: "internal"; message: string };
2659
+ export type BridgeError = { kind: "server"; serverCode: number; serverText: string; errorType?: string; backoffSeconds?: number } | { kind: "timeout" } | { kind: "not-connected" } | { kind: "withdrawn" } | { kind: "disconnected"; reason: string } | { kind: "invalid-argument"; field: string; reason: string } | { kind: "protocol-violation"; reason: string } | { kind: "crypto"; operation: string } | { kind: "storage"; operation: string } | { kind: "no-recipient-device"; attempted: number } | { kind: "internal"; message: string };
2659
2660
 
2660
2661
  /**
2661
2662
  * Public portion of one pre-key in a supplied pairwise session bundle.
@@ -3031,6 +3032,21 @@ export interface CoverPhotoUploadInput {
3031
3032
  timestamp: string;
3032
3033
  }
3033
3034
 
3035
+ /**
3036
+ * What the client\'s connection state means for work handed to it now.
3037
+ *
3038
+ * The core\'s `Reachability`, carried across unflattened. A refused call says
3039
+ * what happened to that attempt; this says what the client is, which is the
3040
+ * only thing that answers whether asking again is worth it — so it is read
3041
+ * when the question comes up rather than stamped onto an error that is a fact
3042
+ * about one instant.
3043
+ *
3044
+ * `unknown` is not one of the core\'s: the enum is `#[non_exhaustive]`, and a
3045
+ * state added upstream has no name here yet. Naming the gap beats reporting it
3046
+ * as one of its neighbours.
3047
+ */
3048
+ export type Reachability = "reachable" | "reconnecting" | "paused" | "unsupervised" | "finished" | "unknown";
3049
+
3034
3050
  export interface AllocationBucketSnapshot {
3035
3051
  allocatedBytes: number;
3036
3052
  allocations: number;
@@ -4023,8 +4039,27 @@ export class WasmWhatsAppClient {
4023
4039
  * neither constructs protocol nodes nor translates consumer-facing names.
4024
4040
  */
4025
4041
  queryUsync(query: UsyncQuery): Promise<UsyncResponse>;
4042
+ /**
4043
+ * What work handed to the client right now can expect.
4044
+ *
4045
+ * `isConnected()` and `isLoggedIn()` each answer half of it; this answers
4046
+ * the question a refused caller actually has, which is whether asking
4047
+ * again is worth it. `reconnecting` comes back on its own, `paused` comes
4048
+ * back on `resume`, `unsupervised` needs a `run()`, and `finished` needs a
4049
+ * new client.
4050
+ *
4051
+ * Read when the question comes up rather than carried on the error: a
4052
+ * refusal is a fact about one instant, and a connection can be lost right
4053
+ * after a call was admitted or restored right after one was refused.
4054
+ */
4055
+ reachability(): Reachability;
4026
4056
  /**
4027
4057
  * Mark messages as read by sending read receipts.
4058
+ *
4059
+ * Held per chat rather than once for the batch: the core stamps the
4060
+ * receipt's timestamp inside `mark_as_read`, so each one is sampled after
4061
+ * its own wait rather than at the call the host made. Only the first of
4062
+ * them can be withdrawn — after that the call has already sent something.
4028
4063
  */
4029
4064
  readMessages(keys: ReadMessageKey[]): Promise<void>;
4030
4065
  /**
@@ -4410,6 +4445,45 @@ export class WasmWhatsAppClient {
4410
4445
  * `kind === 'timeout'`.
4411
4446
  */
4412
4447
  waitForSocket(timeout_ms: number): Promise<void>;
4448
+ /**
4449
+ * Wait until the client can reach the server again, and report what ended
4450
+ * the wait.
4451
+ *
4452
+ * Never resolves to `reconnecting` — that is the one state it waits out.
4453
+ * Bounded by the client's lifetime rather than a duration, because the
4454
+ * reconnect backoff is jittered and followed by a handshake; a caller that
4455
+ * wants a deadline races this against one of its own.
4456
+ *
4457
+ * The calls that hold themselves need none of this. It is for the ones
4458
+ * that do not — `sendNode`, `queryNode`, `sendRawMessage` — where only the
4459
+ * caller knows whether the node it is holding survives a new socket.
4460
+ *
4461
+ * It is also how a caller bounds work rather than waiting. Racing a
4462
+ * parked call against a timer abandons the promise but not the call, so a
4463
+ * send still goes out when the reconnect lands; racing this instead
4464
+ * leaves the decision to issue it with the caller.
4465
+ *
4466
+ * Not from an event handler: the core dispatches on its read loop, so a
4467
+ * handler that waits here waits on the connection it is blocking.
4468
+ */
4469
+ waitUntilReachable(): Promise<Reachability>;
4470
+ /**
4471
+ * Let go of every call waiting out a reconnect right now, and return how
4472
+ * many were let go.
4473
+ *
4474
+ * A held call cannot be taken back by dropping its promise: wasm-bindgen
4475
+ * drives the method to completion either way, so racing it against a
4476
+ * deadline bounds the waiting and not the call — it still goes out when
4477
+ * the reconnect lands, and asking again sends the same thing twice. This
4478
+ * is how giving up is said instead: each released call rejects with
4479
+ * `kind: 'withdrawn'` without reaching the core, so nothing it was about
4480
+ * to do happened and re-issuing it is not a repeat.
4481
+ *
4482
+ * Releases what is waiting at the moment of the call and nothing else. It
4483
+ * is not a mode — the next call waits like any other — and it does not
4484
+ * touch the calls that never wait.
4485
+ */
4486
+ withdrawParkedCalls(): number;
4413
4487
  }
4414
4488
 
4415
4489
  /**
@@ -4624,6 +4698,7 @@ export interface InitOutput {
4624
4698
  readonly wasmwhatsappclient_profilePictureUrl: (a: number, b: number, c: number, d: number, e: number, f: number) => number;
4625
4699
  readonly wasmwhatsappclient_queryNode: (a: number, b: number, c: number, d: number) => number;
4626
4700
  readonly wasmwhatsappclient_queryUsync: (a: number, b: number) => number;
4701
+ readonly wasmwhatsappclient_reachability: (a: number) => number;
4627
4702
  readonly wasmwhatsappclient_readMessages: (a: number, b: number) => number;
4628
4703
  readonly wasmwhatsappclient_reconnect: (a: number) => number;
4629
4704
  readonly wasmwhatsappclient_refreshPreKeys: (a: number, b: number) => number;
@@ -4693,6 +4768,8 @@ export interface InitOutput {
4693
4768
  readonly wasmwhatsappclient_votePoll: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number) => number;
4694
4769
  readonly wasmwhatsappclient_waitForConnected: (a: number, b: number) => number;
4695
4770
  readonly wasmwhatsappclient_waitForSocket: (a: number, b: number) => number;
4771
+ readonly wasmwhatsappclient_waitUntilReachable: (a: number) => number;
4772
+ readonly wasmwhatsappclient_withdrawParkedCalls: (a: number) => number;
4696
4773
  readonly getWasmMemoryBytes: () => number;
4697
4774
  readonly __wbg_intounderlyingbytesource_free: (a: number, b: number) => void;
4698
4775
  readonly __wbg_intounderlyingsink_free: (a: number, b: number) => void;
@@ -4707,12 +4784,12 @@ export interface InitOutput {
4707
4784
  readonly intounderlyingsink_write: (a: number, b: number) => number;
4708
4785
  readonly intounderlyingsource_cancel: (a: number) => void;
4709
4786
  readonly intounderlyingsource_pull: (a: number, b: number) => number;
4710
- readonly __wasm_bindgen_func_elem_4358: (a: number, b: number, c: number) => void;
4711
- readonly __wasm_bindgen_func_elem_26619: (a: number, b: number, c: number, d: number) => void;
4712
- readonly __wasm_bindgen_func_elem_26621: (a: number, b: number, c: number, d: number) => void;
4713
- readonly __wasm_bindgen_func_elem_9303: (a: number, b: number, c: number) => void;
4714
- readonly __wasm_bindgen_func_elem_4357: (a: number, b: number, c: number) => void;
4715
- readonly __wasm_bindgen_func_elem_4356: (a: number, b: number) => void;
4787
+ readonly __wasm_bindgen_func_elem_4417: (a: number, b: number, c: number) => void;
4788
+ readonly __wasm_bindgen_func_elem_26574: (a: number, b: number, c: number, d: number) => void;
4789
+ readonly __wasm_bindgen_func_elem_26576: (a: number, b: number, c: number, d: number) => void;
4790
+ readonly __wasm_bindgen_func_elem_9408: (a: number, b: number, c: number) => void;
4791
+ readonly __wasm_bindgen_func_elem_4416: (a: number, b: number, c: number) => void;
4792
+ readonly __wasm_bindgen_func_elem_4415: (a: number, b: number) => void;
4716
4793
  readonly __wbindgen_export: (a: number, b: number) => number;
4717
4794
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
4718
4795
  readonly __wbindgen_export3: (a: number) => void;
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oxidezap/whatsapp-rust-bridge",
3
- "version": "0.16.0",
3
+ "version": "0.18.0",
4
4
  "description": "A high-performance utilities for WhatsApp, powered by Rust and WebAssembly.",
5
5
  "author": "João Lucas <jlucaso@hotmail.com>",
6
6
  "license": "MIT",
@@ -44,16 +44,17 @@
44
44
  "build:wasm": "wasm-pack build --target web --out-dir pkg --no-pack",
45
45
  "build:wasm:dev": "wasm-pack build --target web --out-dir pkg --no-pack --dev",
46
46
  "build:ts": "bun build ts/index.ts --minify --outfile dist/index.js --target node && cp pkg/whatsapp_rust_bridge_bg.wasm dist/ && cp ts/proto-types.d.ts dist/proto-types.d.ts && cp ts/proto-types.d.ts pkg/proto-types.d.ts && printf 'export { proto } from \"./index.js\";\\n' > dist/proto-types.js",
47
- "postbuild": "tsc -p tsconfig.json --outDir dist && rm -f dist/macro.d.ts && rm -rf dist/generated && bun run scripts/finalize-dist.ts",
48
- "build": "bun run gen && bun run build:wasm && bun run build:ts && bun run postbuild",
49
- "build:dev": "bun run gen && bun run build:wasm:dev && bun run build:ts && bun run postbuild",
50
- "build:profile": "cargo build --profile profiling --target wasm32-unknown-unknown && wasm-bindgen --target web --out-dir pkg --keep-debug target/wasm32-unknown-unknown/profiling/whatsapp_rust_bridge.wasm && wasm-tools strip pkg/whatsapp_rust_bridge_bg.wasm -o pkg/whatsapp_rust_bridge_bg.wasm && bun run build:ts && bun run postbuild",
51
- "build:memory-profile": "cargo build --profile profiling --target wasm32-unknown-unknown --features memory-profiling && wasm-bindgen --target web --out-dir pkg --keep-debug target/wasm32-unknown-unknown/profiling/whatsapp_rust_bridge.wasm && wasm-tools strip pkg/whatsapp_rust_bridge_bg.wasm -o pkg/whatsapp_rust_bridge_bg.wasm && bun run build:ts && bun run postbuild",
47
+ "build:finalize": "tsc -p tsconfig.json --outDir dist && rm -f dist/macro.d.ts && rm -rf dist/generated && bun run scripts/finalize-dist.ts",
48
+ "build": "bun run gen && bun run build:wasm && bun run build:ts && bun run build:finalize",
49
+ "build:dev": "bun run gen && bun run build:wasm:dev && bun run build:ts && bun run build:finalize",
50
+ "build:profile": "cargo build --profile profiling --target wasm32-unknown-unknown && wasm-bindgen --target web --out-dir pkg --keep-debug target/wasm32-unknown-unknown/profiling/whatsapp_rust_bridge.wasm && wasm-tools strip pkg/whatsapp_rust_bridge_bg.wasm -o pkg/whatsapp_rust_bridge_bg.wasm && bun run build:ts && bun run build:finalize",
51
+ "build:memory-profile": "cargo build --profile profiling --target wasm32-unknown-unknown --features memory-profiling && wasm-bindgen --target web --out-dir pkg --keep-debug target/wasm32-unknown-unknown/profiling/whatsapp_rust_bridge.wasm && wasm-tools strip pkg/whatsapp_rust_bridge_bg.wasm -o pkg/whatsapp_rust_bridge_bg.wasm && bun run build:ts && bun run build:finalize",
52
52
  "bump:wacore": "cargo update -p whatsapp-rust && bun run build",
53
53
  "example": "NODE_TLS_REJECT_UNAUTHORIZED=0 bun run examples/connect.ts",
54
54
  "test:rust": "wasm-pack test --node",
55
55
  "check:size": "bun run scripts/check-size.ts",
56
56
  "check:wasm-shape": "node scripts/check-wasm-shape.mjs",
57
+ "check:test-clock": "bun run scripts/check-test-clock.ts",
57
58
  "measure:fn-sizes": "node scripts/wasm-fn-sizes.mjs pkg/whatsapp_rust_bridge_bg.wasm",
58
59
  "measure:zone-peak": "node scripts/wasm-zone-peak.mjs pkg/whatsapp_rust_bridge_bg.wasm",
59
60
  "prepack": "bun run scripts/check-pack.ts",