feat(sdk): Effect v4 + @effect/openapi-generator; typed pf.api & example ladder
Drop Orval for the first-party @effect/openapi-generator (OpenAPI 3.1 -> Effect Schema + a typed HttpClient client) and bump effect 3.19 -> 4.0.0-beta.98. Port the hand-written surfaces to the v4 API (Result over Either, Context.Service, Codec, Literals/Union arrays, Stream/Schedule/ Effect renames). Transport (CA-pinning fetch) and the reconnecting SSE source are kept intact. Make the SDK approachable for non-Effect users: - Add pf.api.* on the Promise facade: the generated client surfaced as typed, Promise-native methods (await pf.api.listPairedClients()), so REST calls are autocompleted and checked instead of stringly-typed pf.request(method, path, body) + `as` casts. Zero-drift veneer over make(httpClient), backed by the same pinning fetch. pf.request stays as the untyped escape hatch. - Re-tier examples into a 1-4 complexity ladder, rewritten onto pf.api.* (the typed payloads caught a wrong `launch` shape in provider-sync); the Effect example is labelled advanced. Add examples/ to tsconfig so they are typechecked (stops rot). typecheck + 19 tests green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
// The flagship hook-with-a-decision pattern (Promise facade): watch pairing requests, notify,
|
||||
// and approve/deny THROUGH the API — asynchronously, the punktfunk way (hooks never veto).
|
||||
// ── Example 2/4 · event → decision ──────────────────────────────────────────────────────────
|
||||
// The flagship pattern: watch pairing requests, notify yourself, and approve/deny THROUGH the
|
||||
// typed API — asynchronously, the punktfunk way (hooks never veto). Every call is checked and
|
||||
// autocompleted; no hand-written paths, no casts.
|
||||
import { connect } from "../src/index.js";
|
||||
|
||||
const pf = await connect();
|
||||
@@ -7,9 +9,13 @@ console.log("watching for pairing requests…");
|
||||
|
||||
pf.events.on("pairing.pending", async (e) => {
|
||||
console.log(`pairing request: ${e.device.name} (${e.device.fingerprint})`);
|
||||
// Wire your real notifier here (ntfy, Pushover, Home Assistant, …), then decide:
|
||||
// const pending = await pf.request("GET", "/native/pending") as { id: number }[];
|
||||
// await pf.request("POST", `/native/pending/${pending[0].id}/approve`);
|
||||
|
||||
// Wire your real notifier here (ntfy, Pushover, Home Assistant, …). Then decide by calling
|
||||
// the API — find the pending device by fingerprint and approve it (send `{}` to keep the
|
||||
// name it knocked with):
|
||||
const pending = await pf.api.listPendingDevices();
|
||||
const match = pending.find((d) => d.fingerprint === e.device.fingerprint);
|
||||
if (match) await pf.api.approvePendingDevice(String(match.id), { payload: {} });
|
||||
});
|
||||
pf.events.on("pairing.completed", (e) => console.log(`paired: ${e.device.name}`));
|
||||
pf.events.on("pairing.denied", (e) => console.log(`denied: ${e.device.name}`));
|
||||
|
||||
Reference in New Issue
Block a user