@kehto/services 0.2.0

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 ADDED
@@ -0,0 +1,85 @@
1
+ # @kehto/services
2
+
3
+ Reference service handlers for the napplet protocol — audio, notifications, identity, relay pool, cache, keys (stub), media (stub), notify, theme.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @kehto/services
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ `@kehto/services` ships the reference implementations of the `ServiceHandler` contract defined by `@kehto/runtime`. Each factory returns an object that the runtime routes NIP-5D envelopes to based on the domain prefix of the incoming message type (e.g., `identity.*` goes to the handler registered under `identity`).
14
+
15
+ Host apps wire services into the runtime via `runtime.registerService(name, handler)`. The services are browser-agnostic — they have no DOM dependency. Browser-specific behaviors (audio element pool, OS notifications) are delivered through host-supplied callbacks.
16
+
17
+ Canonical v1.2 posture:
18
+
19
+ - The v1.1 signer service is deleted outright. Its responsibilities split into two: read-only identity lookups go through `createIdentityService` (`getPublicKey`, `getRelays`, `getProfile`, `getFollows`, `getList`, `getZaps`, `getMutes`, `getBlocked`, `getBadges`); signing happens inside the shell as part of `relay.publish` / `relay.publishEncrypted` and is never exposed to napplets.
20
+ - `createKeysService` and `createMediaService` are stub-only in v1.3 — they accept the canonical envelopes and return well-formed responses, but real host backends (OS keybinding registration, audio/video playback control) must be plugged in by the host app in future milestones.
21
+ - `createNotifyService` (NIP-5D `notify.*` NUB) coexists with the legacy `createNotificationService` (ifc-emit `notifications:*` channel). Both may be registered simultaneously until the legacy handler is retired.
22
+
23
+ ## Quick Start
24
+
25
+ ```ts
26
+ import {
27
+ createIdentityService,
28
+ createNotificationService,
29
+ } from '@kehto/services';
30
+
31
+ // Identity service — read-only lookups backed by a signer adapter.
32
+ runtime.registerService(
33
+ 'identity',
34
+ createIdentityService({
35
+ getPublicKey: () => signer.getPublicKey(),
36
+ getRelays: () => signer.getRelays(),
37
+ getProfile: (pk) => nostrClient.fetchProfile(pk),
38
+ }),
39
+ );
40
+
41
+ // Notification service — legacy ifc-emit channel, browser badge fan-out.
42
+ runtime.registerService(
43
+ 'notifications',
44
+ createNotificationService({ onChange: (list) => updateBadge(list) }),
45
+ );
46
+ ```
47
+
48
+ ## Public API
49
+
50
+ Each factory returns a `ServiceHandler` registrable via `runtime.registerService()`. The bullets below note the canonical NIP-5D domain the handler owns and the ACL capability napplets need in order to reach it.
51
+
52
+ ### Identity NUB
53
+ - [`createIdentityService`](../../docs/api/functions/_kehto_services.createIdentityService.html) — `identity.*` reads (`identity:read`). No signing surface; shell mediates signing internally.
54
+
55
+ ### Notify NUB
56
+ - [`createNotifyService`](../../docs/api/functions/_kehto_services.createNotifyService.html) — canonical `notify.*` envelopes (`notify:send` / `notify:channel`).
57
+ - [`createNotificationService`](../../docs/api/functions/_kehto_services.createNotificationService.html) — legacy ifc-emit `notifications:*` channel; coexists with `createNotifyService` until retired.
58
+
59
+ ### Relay NUB
60
+ - [`createRelayPoolService`](../../docs/api/functions/_kehto_services.createRelayPoolService.html) — `relay.publish`, `relay.publishEncrypted`, `relay.subscribe` fan-out (`relay:read` / `relay:write`).
61
+ - [`createCacheService`](../../docs/api/functions/_kehto_services.createCacheService.html) — offline event cache (`cache:read` / `cache:write`).
62
+ - [`createCoordinatedRelay`](../../docs/api/functions/_kehto_services.createCoordinatedRelay.html) — composite service that bundles relay-pool + cache with read-through behavior.
63
+
64
+ ### Keys NUB (stub in v1.3)
65
+ - [`createKeysService`](../../docs/api/functions/_kehto_services.createKeysService.html) — `keys.bind/unbind/bindings` stub (`keys:bind` / `keys:forward`). Plug a real backend via the `onBind`/`onForward` hooks when the host supports OS key registration.
66
+
67
+ ### Media NUB (stub in v1.3)
68
+ - [`createMediaService`](../../docs/api/functions/_kehto_services.createMediaService.html) — `media.*` playback/transport stub (`media:control`). Plug a real media backend via the service options.
69
+
70
+ ### Theme NUB
71
+ - [`createThemeService`](../../docs/api/functions/_kehto_services.createThemeService.html) — `theme.get` + `theme.changed` fan-out (`theme:read`). Returns a `ThemeService` with `publishTheme()` / `setTheme()` utilities for host-side updates.
72
+
73
+ ### Audio (legacy ifc-emit)
74
+ - [`createAudioService`](../../docs/api/functions/_kehto_services.createAudioService.html) — `audio:*` ifc-emit topic handler. Browser-agnostic registry of per-window audio sources; host wires `onChange` to update transport UI.
75
+
76
+ ### Types
77
+ `AudioSource`, `AudioServiceOptions`, `Notification`, `NotificationServiceOptions`, `IdentityServiceOptions`, `RelayPoolServiceOptions`, `CacheServiceOptions`, `CoordinatedRelayOptions`, `KeysServiceOptions`, `MediaServiceOptions`, `NotifyServiceOptions`, `ThemeServiceOptions`, `ThemeService`.
78
+
79
+ ## API Reference
80
+
81
+ Full API reference: [docs/api/@kehto/services/](../../docs/api/modules/_kehto_services.html) (generated via `pnpm docs:api`).
82
+
83
+ ## License
84
+
85
+ MIT