@hyperfrontend/features/hostee

Hostee

Hostee-side SDK for feature apps — feature initialization, contract declaration, and lifecycle.

import { createFeature } from '@hyperfrontend/features/hostee'

const feature = createFeature({
  name: 'clock',
  contract: {
    emitted: [{ type: 'tick' }],
    accepted: [{ type: 'set-timezone' }],
  },
})

await feature.ready()
feature.on('set-timezone', ({ tz }) => render(tz))
setInterval(() => feature.send('tick', Date.now()), 1000)

API

ExportPurpose
createFeatureConnect a feature app to its host; returns send/on/ready/close.
FeatureHandleType of the handle returned by createFeature.

ready() resolves once the host connection is established. send emits a contract action to the host; on subscribes to host messages and the open/close/error lifecycle events. close disconnects from the host.

API Reference

ƒ Functions

§function

createFeature(options: FeatureOptions): FeatureHandle

Initializes a feature app on the hostee side and waits for the host connection.
Creates a nexus broker for the feature, resolves the host window, and returns a handle for messaging and lifecycle.

Parameters

NameTypeDescription
§options
FeatureOptions
Feature name and contract.

Returns

FeatureHandle
A handle exposing send, on, ready, and close.

Example

Initializing a clock feature

const feature = createFeature({ name: 'clock', contract })
feature.ready().then(() => feature.send('timeUpdated', { time: Date.now() }))
feature.on('setTimezone', (data) => console.log(data))

Interfaces

§interface

FeatureHandle

Public handle returned by the hostee-side feature factory.

Properties

§interface

ActionDescription

Description of a single action a feature can emit or accept.
Structurally compatible with nexus's channel contract action shape so the same contract can drive both messaging and the shell type generator.

Properties

§description?:string
Human-readable explanation of the action, surfaced in tooling.
§respondsWith?:string
When this action is used as a request, the type of the action in the other direction that answers it.
§schema?:object
Optional JSON-schema-like shape describing the action payload.
§type:string
Wire type string that identifies the action.
§interface

FeatureContract

The set of actions a feature emits to, and accepts from, its counterpart.
This is the same shape the on-disk *.contract.json files and the shell generator consume.

Properties

§accepted:ActionDescription[]
Actions this side handles from the other side.
§emitted:ActionDescription[]
Actions this side sends to the other side.
§interface

FeatureOptions

Options accepted by the hostee-side feature factory.

Properties

§contract:FeatureContract
Contract describing the actions the feature emits and accepts.
§name:string
Stable identifier for the feature, used to name its messaging channel.
§resetBody?:boolean
Whether to neutralize the feature page's body margins/padding; defaults to true.
§interface

RequestOptions

Per-request settings accepted by request.

Properties

§timeoutMs?:number
Milliseconds to wait for the response before rejecting; defaults to 30000.

Types

§type

RequestHandler

Answers one request type; may return the response value directly or a promise of it.
type RequestHandler = (data: unknown) => unknown