WeSDK - The SDK Noone Asked For

Core Concepts

This page explains the behavior model behind WeSDK v2.

Promise-First Execution Model

All public APIs return Promises.

try {
	const res = await sdk.getLocation();
	console.log(res);
} catch (err) {
	console.error(err);
}

Callback options are still accepted on most APIs for compatibility, but Promise handling is the recommended default.

Bridge Lifecycle

The SDK dispatches calls through a detected bridge (LuffaJSBridge, WeixinJSBridge, QQJSBridge by default).

Runtime Detection and Capability Discovery

Use runtime APIs before invoking optional features:

Capability reason values:

Response Normalization

SDK responses are normalized to reduce platform inconsistencies.

Every response may include:

This makes generic success/failure handling easier.

Error Model

Failures reject with LuffaWeSDKError carrying:

Common codes include:

See Error Reference.

Diagnostics

You can attach onDiagnostics via config to receive internal lifecycle events.

Typical events:

Multiple SDK Instances

Use create() to isolate configuration and runtime behavior between modules/tests.

const sdkA = sdk.create({ debug: true, readyTimeout: 5000 });
const sdkB = sdk.create({ debug: false, readyTimeout: 15000 });

Migration Mindset

When upgrading from legacy:

See Migration v1 to v2.