@oxidezap/whatsapp-rust-bridge 0.22.1 → 0.23.1

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.
@@ -1,5 +1,4 @@
1
1
  import { BinaryReader as BaseBinaryReader, BinaryWriter as BaseBinaryWriter } from "@bufbuild/protobuf/wire";
2
- import { Buffer } from "node:buffer";
3
2
  /** Index of the first UTF-16 code unit with no partner, or -1 when well-formed. */
4
3
  export declare function unpairedSurrogateIndex(value: string): number;
5
4
  /**
@@ -66,15 +65,8 @@ export declare class BinaryWriter extends BaseBinaryWriter {
66
65
  fixed64(value: NumericInput): this;
67
66
  sfixed64(value: NumericInput): this;
68
67
  }
69
- /**
70
- * BinaryReader specialized for ts-proto's 64-bit output contract. Buf's own
71
- * 64-bit methods materialize a BigInt and then a decimal string; the `*Value()`
72
- * methods below avoid both intermediates, while the inherited methods retain
73
- * Buf's public BigInt/string behavior for direct users.
74
- */
75
68
  export declare class BinaryReader extends BaseBinaryReader {
76
- protected readonly utf8Buffer: Buffer;
77
- private readonly wireBytes;
69
+ protected readonly wireBytes: Uint8Array;
78
70
  constructor(buf: Uint8Array);
79
71
  protected checkBounds(): void;
80
72
  private readVarintWords;
@@ -1 +1 @@
1
- export { proto } from "./index.js";
1
+ export { proto } from "./host.js";
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The one JS surface every entrypoint publishes.
3
+ *
4
+ * `ts/index.ts` (default: finds and loads the wasm itself) and `ts/host.ts`
5
+ * (host-supplied wasm bytes) both re-export this module, so the API exists in
6
+ * exactly one source. A method added here reaches both entrypoints; a typo in
7
+ * one entrypoint cannot drift the other's client signature.
8
+ */
9
+ export * from "./whatsapp_rust_bridge.js";
10
+ export { encodeProto, decodeProto, decodeProtoBatch, UnpairedSurrogateError, type ProtoDecodeReport, } from "./proto.js";
11
+ export { BinaryReader, InvalidUtf8CountingReader, longToBigInt, type Int64, type Long, } from "./proto-reader.js";
12
+ export { decodeEventWireEnvelope, decodeMessageWireBatch, decodeReceiptWireBatch, decodeServerAckWireBatch, encodeEventWireEnvelope, encodeMessageWireBatch, encodeReceiptWireBatch, encodeServerAckWireBatch, EVENT_SEGMENT_KIND_MESSAGE, EVENT_SEGMENT_KIND_RECEIPT, EVENT_SEGMENT_KIND_SERVER_ACK, MESSAGE_WIRE_INFO_RECORD_WIDTH, type EventWireSegment, type MessageWireBatchView, type MessageWireEntry, type MessageWireInfo, type PackedWireBatch, type ReceiptWireData, type ServerAckWireData, type WireJid, } from "./wire-info.js";
13
+ export { proto } from "./proto-namespace.js";
14
+ import type { WhatsAppEventHandler, JsTransportCallbacks, JsHttpClientConfig, JsStoreCallbacks, CacheConfig, ClientPolicies } from "./whatsapp_rust_bridge.js";
15
+ import type { WasmWhatsAppClient } from "./whatsapp_rust_bridge.js";
16
+ export declare const initWasmEngine: (logger?: any, crypto?: any) => void;
17
+ export declare const createWhatsAppClient: (transport: JsTransportCallbacks, httpClient: JsHttpClientConfig, onEvent?: WhatsAppEventHandler | null, store?: JsStoreCallbacks | null, cache?: CacheConfig | null, version?: readonly [number, number, number] | null, wantedPreKeyCount?: number | null, dangerSkipCertChainVerify?: boolean | null, policies?: ClientPolicies | null) => Promise<WasmWhatsAppClient>;
package/dist/wasm.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Type declaration for the `./wasm` export subpath
3
+ * (`dist/whatsapp_rust_bridge_bg.wasm`).
4
+ *
5
+ * A `.wasm` binary has no per-host type story — workerd delivers a compiled
6
+ * `WebAssembly.Module`, other hosts deliver bytes — so this declares the one
7
+ * thing every host's value has in common: it is exactly wasm-bindgen's
8
+ * `SyncInitInput`, the input `initSync` from
9
+ * `@oxidezap/whatsapp-rust-bridge/host` already takes. No platform is named
10
+ * in the contract:
11
+ *
12
+ * ```ts
13
+ * import wasm from "@oxidezap/whatsapp-rust-bridge/wasm";
14
+ * import { initSync } from "@oxidezap/whatsapp-rust-bridge/host";
15
+ * initSync({ module: wasm });
16
+ * ```
17
+ *
18
+ * Hand-written rather than emitted: tsc's emitDeclarationOnly pass does not
19
+ * copy a lone `.d.ts` source, and the content is one declaration.
20
+ */
21
+
22
+ import type { SyncInitInput } from "./whatsapp_rust_bridge.js";
23
+
24
+ declare const wasm: SyncInitInput;
25
+
26
+ export default wasm;
@@ -44,10 +44,9 @@ export interface JsTransportHandle {
44
44
 
45
45
  /**
46
46
  * Every Promise handed back to the bridge must settle, including on failure:
47
- * reject rather than leaving it pending. The bridge awaits it through a
48
- * wasm-bindgen `JsFuture`, whose resolve/reject pair is only released when the
49
- * promise settles, so a promise that never settles retains two JS handles for
50
- * the life of the process.
47
+ * reject rather than leaving it pending. The bridge awaits them through a
48
+ * wasm-bindgen `JsFuture`; an overlapping teardown cancels only the wait that
49
+ * would otherwise form a callback/teardown cycle.
51
50
  */
52
51
  export interface JsTransportCallbacks {
53
52
  connect(handle: JsTransportHandle): void | Promise<void>;
@@ -3768,6 +3767,13 @@ export class WasmWhatsAppClient {
3768
3767
  deleteQuickReply(id: string): Promise<void>;
3769
3768
  /**
3770
3769
  * Disconnect the client and flush pending state to storage.
3770
+ *
3771
+ * This is an explicit teardown barrier: the promise does not resolve until
3772
+ * the core has flushed persistence and the bridge-owned background tasks
3773
+ * have been stopped. The shared gate makes concurrent `disconnect()` and
3774
+ * `logout()` calls idempotent instead of entering the core teardown paths
3775
+ * together. If a host disconnect callback re-enters teardown, the callback
3776
+ * wait is cancelled so the two teardown operations cannot wait on each other.
3771
3777
  */
3772
3778
  disconnect(): Promise<void>;
3773
3779
  /**
@@ -5005,12 +5011,12 @@ export interface InitOutput {
5005
5011
  readonly intounderlyingsink_write: (a: number, b: number) => number;
5006
5012
  readonly intounderlyingsource_cancel: (a: number) => void;
5007
5013
  readonly intounderlyingsource_pull: (a: number, b: number) => number;
5008
- readonly __wasm_bindgen_func_elem_4670: (a: number, b: number, c: number) => void;
5009
- readonly __wasm_bindgen_func_elem_28628: (a: number, b: number, c: number, d: number) => void;
5010
- readonly __wasm_bindgen_func_elem_28630: (a: number, b: number, c: number, d: number) => void;
5011
- readonly __wasm_bindgen_func_elem_9914: (a: number, b: number, c: number) => void;
5012
- readonly __wasm_bindgen_func_elem_4669: (a: number, b: number, c: number) => void;
5013
- readonly __wasm_bindgen_func_elem_4668: (a: number, b: number) => void;
5014
+ readonly __wasm_bindgen_func_elem_4655: (a: number, b: number, c: number) => void;
5015
+ readonly __wasm_bindgen_func_elem_28615: (a: number, b: number, c: number, d: number) => void;
5016
+ readonly __wasm_bindgen_func_elem_28617: (a: number, b: number, c: number, d: number) => void;
5017
+ readonly __wasm_bindgen_func_elem_9885: (a: number, b: number, c: number) => void;
5018
+ readonly __wasm_bindgen_func_elem_4654: (a: number, b: number, c: number) => void;
5019
+ readonly __wasm_bindgen_func_elem_4653: (a: number, b: number) => void;
5014
5020
  readonly __wbindgen_export: (a: number, b: number) => number;
5015
5021
  readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
5016
5022
  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.22.1",
3
+ "version": "0.23.1",
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",
@@ -22,6 +22,14 @@
22
22
  "import": "./dist/index.js",
23
23
  "types": "./dist/index.d.ts"
24
24
  },
25
+ "./host": {
26
+ "import": "./dist/host.js",
27
+ "types": "./dist/host.d.ts"
28
+ },
29
+ "./wasm": {
30
+ "types": "./dist/wasm.d.ts",
31
+ "default": "./dist/whatsapp_rust_bridge_bg.wasm"
32
+ },
25
33
  "./proto-types": {
26
34
  "import": "./dist/proto-types.js",
27
35
  "types": "./dist/proto-types.d.ts"
@@ -43,7 +51,7 @@
43
51
  "gen": "bun run gen:proto-codec && bun run gen:proto-types && bun run gen:bridge-types",
44
52
  "build:wasm": "wasm-pack build --target web --out-dir pkg --no-pack",
45
53
  "build:wasm:dev": "wasm-pack build --target web --out-dir pkg --no-pack --dev",
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",
54
+ "build:ts": "bun run scripts/build-shared-entrypoints.ts && cp pkg/whatsapp_rust_bridge_bg.wasm dist/ && cp ts/wasm.d.ts dist/wasm.d.ts && 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 \"./host.js\";\\n' > dist/proto-types.js",
47
55
  "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
56
  "build": "bun run gen && bun run build:wasm && bun run build:ts && bun run build:finalize",
49
57
  "build:dev": "bun run gen && bun run build:wasm:dev && bun run build:ts && bun run build:finalize",