@direct.dev/sdk 1.0.0 → 1.0.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.
package/README.md CHANGED
@@ -13,7 +13,7 @@
13
13
  </p>
14
14
  </div>
15
15
 
16
- A drop-in `fetch` wrapper for [Direct.dev](https://direct.dev/) RPC endpoints. Your existing code keeps working — Direct.dev quietly takes over JSON-RPC calls to its own URLs and serves them faster, with caching, sync, and failover built in. Everything else passes through to native `fetch` untouched.
16
+ A drop-in `fetch` wrapper for [Direct.dev](https://direct.dev/) RPC endpoints. Your existing code keeps working — Direct.dev quietly takes over JSON-RPC requests to its own URLs and serves them faster, with caching, sync, and failover built in.
17
17
 
18
18
  ## Highlights
19
19
 
@@ -21,13 +21,13 @@ A drop-in `fetch` wrapper for [Direct.dev](https://direct.dev/) RPC endpoints. Y
21
21
  Popular requests are answered from a local cache; the rest are routed through the Direct.dev edge.
22
22
 
23
23
  **Less bandwidth**<br />
24
- Direct Sync streams only what changed since your last call, instead of resending the full payload every time.
24
+ Direct Sync streams only what changed since your last request, instead of resending the full payload every time.
25
25
 
26
26
  **Compact wire format**<br />
27
27
  Direct Wire is a binary protocol tuned for Web3 traffic — smaller frames and faster decode than JSON-RPC.
28
28
 
29
29
  **Built-in failover**<br />
30
- Calls reroute through a healthy path automatically when an upstream is unavailable. No retry logic to write.
30
+ Requests reroute through a healthy path automatically when an upstream is unavailable. No retry logic to write.
31
31
 
32
32
  **Drop-in**<br />
33
33
  Plugs into native `fetch`, so viem, ethers, and your own code work unchanged. Only Direct.dev URLs are intercepted.
@@ -40,7 +40,7 @@ npm install @direct.dev/sdk
40
40
 
41
41
  ## Quick start
42
42
 
43
- Call `install()` once at app startup and you're done:
43
+ Run `install()` once at app startup and you're done:
44
44
 
45
45
  ```ts
46
46
  import { install } from "@direct.dev/sdk";
@@ -57,7 +57,7 @@ const { result } = await res.json();
57
57
  // "0x134a1c0"
58
58
  ```
59
59
 
60
- That's it. Every call to a Direct.dev RPC URL now goes through the SDK; everything else still hits native `fetch`.
60
+ That's it. Every request to a Direct.dev RPC URL now goes through the SDK.
61
61
 
62
62
  ### With options
63
63
 
@@ -157,14 +157,14 @@ install({
157
157
  | --- | --- | --- | --- |
158
158
  | `logging.client` | `"silent" \| "error" \| "warn" \| "info" \| "debug"` | `"warn"` | Operational / lifecycle log verbosity. |
159
159
  | `logging.requests` | `"off" \| "summary" \| "debug"` | `"off"` | Per-request tracing. |
160
- | `logging.onEvent` | `(event) => void` | — | Structured event sink. Replaces console output when set. |
160
+ | `logging.onEvent` | `(event: LogEvent) => void` | — | Structured event sink. Replaces console output when set. |
161
161
  | `fetch` | `typeof fetch` | `globalThis.fetch` | Underlying fetch to wrap. |
162
162
  | `createWebSocket` | `(url) => WebSocket` | `globalThis.WebSocket` | WebSocket factory for Direct Wire sync. |
163
163
  | `preload` | `string[]` | auto from `<link rel="preload">` | Endpoint URLs to warm at startup. In the browser, the SDK already picks up `<link rel="preload">` tags automatically — use this option for SSR / non-browser runtimes, or to add endpoints not declared in the HTML. |
164
164
 
165
165
  ### `fetch`
166
166
 
167
- Wrap a specific implementation instead of `globalThis.fetch`. Useful in tests, polyfilled environments, or when you want a `createFetch()` instance that bypasses an existing `install()`:
167
+ Wrap a specific implementation instead of `globalThis.fetch`. Useful in tests, custom runtimes, or when you need a `createFetch()` instance that bypasses an existing `install()`:
168
168
 
169
169
  ```ts
170
170
  const directFetch = createFetch({
@@ -257,13 +257,17 @@ Debug example (a single request):
257
257
  Get events as structured objects — useful for dashboards, telemetry, or piping into your own observability stack:
258
258
 
259
259
  ```ts
260
+ import { install, type LogEvent } from "@direct.dev/sdk";
261
+
262
+ const onDirectEvent = (event: LogEvent) => {
263
+ dashboard.push(event);
264
+ };
265
+
260
266
  install({
261
267
  logging: {
262
268
  client: "debug",
263
269
  requests: "debug",
264
- onEvent(event) {
265
- dashboard.push(event);
266
- },
270
+ onEvent: onDirectEvent,
267
271
  },
268
272
  });
269
273
  ```
@@ -271,7 +275,7 @@ install({
271
275
  Event shape:
272
276
 
273
277
  ```ts
274
- type DirectLogEvent = {
278
+ type LogEvent = {
275
279
  level: "debug" | "info" | "warn" | "error";
276
280
  name: string;
277
281
  value: Record<string, unknown>;
@@ -293,7 +297,7 @@ type DirectLogEvent = {
293
297
  - `request_handled`
294
298
  - `block.state_probe`
295
299
 
296
- Typed helper unions live in `@direct.dev/client`: `KnownDirectLogEvent`, `StableDirectLogEvent`, `DebugDirectLogEvent`.
300
+ The SDK exports `LogEvent`, `LoggingOptions`, and `CreateFetchOptions` for typed integrations.
297
301
 
298
302
  ## Inspecting the live client
299
303
 
@@ -330,8 +334,6 @@ The SDK only takes over POST requests whose body is JSON-RPC and whose URL match
330
334
  - `https://staging.rpc.direct.dev/v1/<projectId>.<token>/<networkId>`
331
335
  - `https://prod.rpc.direct.dev/v1/<projectId>.<token>/<networkId>`
332
336
 
333
- Everything else — REST APIs, image loads, third-party APIs — passes straight through to native `fetch`.
334
-
335
337
  ## License
336
338
 
337
339
  Provided under the [Direct.dev Terms and Conditions](https://direct.dev/terms). Use of this package requires agreement to those terms.