Commit 7637a62
authored
Allow passing a backend into static methods (#1724)
# Allowing passing a backend into static methods
- Upgrades to a `dev` release of the Node and WASM bindings, which changes the way backend configuration is passed for all static methods
- This deprecates the old way of passing configuration in to static methods `Client.someStaticMethod(env, gatewayHost, ...)` and replaces it with a new method that takes a backend. We don't break the old way, but if you use it you will see a deprecation warning in your IDE.
- Makes some changes to the `ClientOptions` to allow callers to pass in a backend explicitly. This lets you re-use the same backend between static methods and instantiated clients like we do on mobile.
- Deprecates the `ApiUrls` and moves those constants to Rust
## Changes
### Design Documentation
- Add comprehensive design document outlining the migration strategy and backwards compatibility approach
### Bindings Updates
- Upgrade `@xmtp/wasm-bindings` from 1.9.1 to 1.10.0-dev.a2bdd0a
- Upgrade `@xmtp/node-bindings` from 1.10.0-dev.55280fa to 1.10.0-dev.a2bdd0a
- Fix method renames: `findInboxIdByIdentifier` → `findInboxIdByIdentity`, member management method updates
- Update `sendSyncRequest` to accept `ArchiveOptions` and `serverUrl` parameters
### New Backend Utilities
- Add `createBackend` utility in both SDKs that wraps `BackendBuilder` with proper environment mapping
- Export `Backend`, `BackendBuilder`, and `createBackend` from both SDK index files
### Type System Refactoring
- Move `appVersion` from `OtherOptions` to `NetworkOptions`
- Extract `DeviceSyncOptions` containing `historySyncUrl` and `disableDeviceSync`
- Update `ClientOptions` to union type: `(NetworkOptions | { backend: Backend }) & DeviceSyncOptions & ...`
- Add runtime validation preventing simultaneous `backend` and `NetworkOptions` usage
### Static Method Migration
- Update all static methods to accept `envOrBackend?: XmtpEnv | Backend` parameter
- Add `resolveBackend` helper that handles backwards compatibility
- Deprecate `env` and `gatewayHost` parameters with JSDoc annotations
- Methods updated:
- `Client.revokeInstallations`
- `Client.fetchInboxStates`
- `Client.canMessage`
- `Client.isAddressAuthorized` (node-sdk only)
- `Client.isInstallationAuthorized` (node-sdk only)
### Client Creation Updates
- Replace `createClient`/`createWasmClient` with `createClientWithBackend`
- Update `getInboxIdForIdentifier` to use `Backend` instead of raw host parameters
- Migrate utility functions (`inboxState`, `installations`) to accept `Backend`
### Testing
- Add comprehensive tests for `createBackend` in both SDKs
- Mock `BackendBuilder.build()` in node-sdk tests for Tokio runtime compatibility
- Use real WASM bindings in browser-sdk tests
- Update test helpers to work with new type system
The migration maintains full backwards compatibility - existing code using `env` and `gatewayHost` parameters continues to work unchanged, while new code can use the more flexible `Backend` approach.
<!-- Macroscope's pull request summary starts here -->
<!-- Macroscope will only edit the content between these invisible markers, and the markers themselves will not be visible in the GitHub rendered markdown. -->
<!-- If you delete either of the start / end markers from your PR's description, Macroscope will append its summary at the bottom of the description. -->
> [!NOTE]
> ### Allow passing a Backend instance into static Client methods across browser and node SDKs
> - Adds a `createBackend` utility (browser and node) that constructs a typed `Backend` from env/apiUrl/gatewayHost options, and exports it from both SDKs.
> - Overloads static methods (`canMessage`, `fetchInboxStates`, `revokeInstallations`, `isAddressAuthorized`, `isInstallationAuthorized`) to accept either a pre-built `Backend` or the legacy `env`+`gatewayHost` strings (now deprecated).
> - Adds a `Client.env` getter so callers can read the environment after initialization; the worker response for `client.init` now includes `env`.
> - Updates `sendSyncRequest` to require `(options: ArchiveOptions, serverUrl: string)`; `ConversationsNavbar` resolves `serverUrl` from `HistorySyncUrls[client.env]`.
> - Expands `XmtpEnv` to an explicit string union (`local | dev | production | testnet-staging | testnet-dev | testnet | mainnet`) and introduces `DeviceSyncOptions` split from `NetworkOptions`.
> - Risk: `sendSyncRequest` signature is breaking — callers that invoke it with no arguments will need to pass `options` and `serverUrl`.
>
> <!-- Macroscope's review summary starts here -->
>
> <sup><a href="https://app.macroscope.com">Macroscope</a> summarized 35cc13b.</sup>
> <!-- Macroscope's review summary ends here -->
>
<!-- macroscope-ui-refresh -->
<!-- Macroscope's pull request summary ends here -->1 parent 26aeb9b commit 7637a62
File tree
45 files changed
+894
-303
lines changed- apps/xmtp.chat/src
- components
- App
- Conversations
- contexts
- helpers
- content-types/content-type-primitives
- packages/xmtp-cli
- src
- commands/client
- utils
- sdks
- agent-sdk
- src
- core
- debug
- util
- browser-sdk
- src
- types
- actions
- utils
- workers
- test
- node-sdk
- scripts
- src
- utils
- test
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
45 files changed
+894
-303
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | 50 | | |
53 | 51 | | |
54 | 52 | | |
| |||
Lines changed: 19 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
2 | 6 | | |
3 | 7 | | |
4 | 8 | | |
| |||
48 | 52 | | |
49 | 53 | | |
50 | 54 | | |
51 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
52 | 70 | | |
53 | 71 | | |
54 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
| 7 | + | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
| |||
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
23 | | - | |
| 25 | + | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| |||
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
125 | | - | |
| 127 | + | |
126 | 128 | | |
127 | 129 | | |
128 | 130 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
149 | | - | |
| 149 | + | |
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
| 2 | + | |
2 | 3 | | |
3 | 4 | | |
4 | 5 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
95 | 93 | | |
96 | 94 | | |
97 | 95 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
91 | | - | |
| 91 | + | |
92 | 92 | | |
93 | 93 | | |
94 | 94 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
| 38 | + | |
38 | 39 | | |
39 | 40 | | |
40 | 41 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
4 | 10 | | |
5 | 11 | | |
6 | 12 | | |
| |||
79 | 85 | | |
80 | 86 | | |
81 | 87 | | |
82 | | - | |
| 88 | + | |
83 | 89 | | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
84 | 96 | | |
85 | 97 | | |
86 | | - | |
87 | 98 | | |
88 | 99 | | |
89 | 100 | | |
90 | | - | |
91 | 101 | | |
92 | 102 | | |
93 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| |||
0 commit comments