@dg-superapp/bridge-adapter-example
v0.2.1
Published
Educational stub adapter showing how to implement BridgeAdapter. NOT FOR PRODUCTION.
Maintainers
Readme
@dg-superapp/bridge-adapter-example
EDUCATIONAL STUB — NOT FOR PRODUCTION USE.
This package is a minimal, in-memory reference implementation of the
BridgeAdaptercontract. It exists solely to show public consumers the shape of a working adapter. Every response is a hardcoded value from an in-memory state object. There is no real backend, no HTTP, no persistence, no retry, no observability, no telemetry.
What it does
Implements BridgeAdapter from @dg-superapp/bridge-core with two
handler responses wired into callHandler():
userProfile— returns a static "Jane Example" profileinitializeMiniApp— returns{ os: "example" }- everything else — returns a structured
UNSUPPORTEDfailure
initialize() and dispose() are no-ops.
What it is for
- Reading as a template for your own adapter
- Running in unit tests where you need a valid
BridgeAdapterwith predictable responses - Demonstrating handler dispatch without pulling in WebView,
flutter_inappwebview, or any other platform-specific plumbing
What it is NOT for
- Production traffic
- Real user data
- Anything that needs network I/O, persistence, encryption, or retry
If you are looking for a real adapter to model after, see
packages/adapter-dg for a full production
implementation with WebView plumbing, error handling, timeout
semantics, and response normalization.
Usage
import { createExampleAdapter } from "@dg-superapp/bridge-adapter-example";
const adapter = createExampleAdapter();
await adapter.initialize();
const result = await adapter.callHandler("userProfile", []);
console.log(result);
// { success: true, data: { userId: "USER_0001", ... }, message: "OK" }How to turn this into a real adapter
- Copy
src/ExampleAdapter.tsinto your own package. - Replace the
SUPPORTED_HANDLERSset and theswitchincallHandler()with calls into your real platform (native bridge, HTTP client, WebView message channel, etc). - Change
platformIdandplatformNameto match your platform. - Register your adapter's factory via
registerAdapterImport()in a module side-effect so the SDK can lazy-load it when your platform is detected.
License
MIT — same as the parent monorepo.
