SDK: host
@pithyx/sdk/host is the desktop’s side of the protocol: it serves one app window over a transport end, checks every call’s parameters and the app’s permissions, and sends events and questions. Apps do not use it; pithyx dev and the desktop do.
Generated from the TSDoc comments of @pithyx/sdk 1.0.0-rc.9 at build time; the text below the headings is the comment in the source.
Interfaces
Section titled “Interfaces”ServeOptions
Section titled “ServeOptions”What serveApp serves an app window with.
Properties
Section titled “Properties”context
Section titled “context”context: Omit<AppContext, 'capabilities'>;The init context; capabilities is filled in from the handlers.
methods
Section titled “methods”methods: MethodHandlers;The handlers of the protocol methods this host serves.
extensions?
Section titled “extensions?”optional extensions?: HostExtensions;Host-only methods for the host’s own apps; see HostExtensions.
onReady?
Section titled “onReady?”optional onReady?: (hello) => void;Called when the app completed the handshake.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
hello |
{ protocol: number; sdk: string; } |
- |
hello.protocol |
number |
The protocol version the app speaks. |
hello.sdk |
string |
The SDK version the app was built with. |
Returns
Section titled “Returns”void
AppConnection
Section titled “AppConnection”The host’s side of one app window’s connection.
Methods
Section titled “Methods”emit()
Section titled “emit()”emit<E>(event, data): void;Sends an event; an event that needs a permission the app does not hold (sharesChanged) is dropped.
permissionsChange also updates the permissions the host checks.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
E extends keyof Events |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
event |
E |
The event name. |
data |
Events[E] |
The event’s data. |
Returns
Section titled “Returns”void
ask<Q>( query, data, timeout): Promise<Queries[Q]["answer"] | undefined>;Asks the app and waits; resolves undefined when it does not answer in time.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Q extends keyof Queries |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
query |
Q |
The question. |
data |
Queries[Q]["data"] |
What the question carries. |
timeout |
number |
How long to wait in milliseconds, for example BEFORE_CLOSE_TIMEOUT. |
Returns
Section titled “Returns”Promise<Queries[Q]["answer"] | undefined>
The app’s answer, or undefined after the timeout or when the connection closed.
close()
Section titled “close()”close(): void;Ends the connection; questions still waiting resolve undefined.
Returns
Section titled “Returns”void
Type Aliases
Section titled “Type Aliases”MethodHandlers
Section titled “MethodHandlers”type MethodHandlers = { [M in MethodName]?: ( params: Methods[M]['params'], ) => Methods[M]['result'] | Promise<Methods[M]['result']>;};The host’s handler per protocol method; a method without a handler is not in capabilities. A handler gets the
checked parameters and returns the result or throws a PithyxError, which goes back to the app as a problem.
HostExtensions
Section titled “HostExtensions”type HostExtensions = Record< string, { validate: boolean; handle: unknown; }>;Methods outside the public protocol that a host serves to its own apps, each with its own parameter check. They are
not versioned, not listed in capabilities, and a host never gives them to a third-party app.
Functions
Section titled “Functions”keepsBrowserMenu()
Section titled “keepsBrowserMenu()”function keepsBrowserMenu(target): boolean;Text fields keep the browser’s menu, so paste and spelling suggestions still work there.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
target |
EventTarget | null |
The target of a contextmenu event. |
Returns
Section titled “Returns”boolean
Whether the target is inside an input, a text area, a select or an editable element.
sdkError()
Section titled “sdkError()”function sdkError(code, params?, detail?): PithyxError;A PithyxError with one of the SDK’s own transport codes.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
code |
| "sdk.method.unknown" | "sdk.request.invalid" | "sdk.request.timeout" | "sdk.transport.closed" | "sdk.protocol.unsupported" | "sdk.transfer.cancelled" | "sdk.backend.endpoint_unknown" | "sdk.backend.unreachable" |
One of sdkErrorCodes. |
params |
Record<string, unknown> |
Values for the translated message. |
detail? |
string |
English fallback text. |
Returns
Section titled “Returns”The error, to throw or to reject with.
serveApp()
Section titled “serveApp()”function serveApp(endpoint, options): AppConnection;Serves one app window over a transport end. Answers hello with init (or refuse with
sdk.protocol.unsupported), then checks each request’s parameters (sdk.request.invalid), the permissions the host
itself checks (app.permission.denied) and whether a handler exists (sdk.method.unknown) before the handler runs.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
endpoint |
Endpoint |
The host’s end of the transport. |
options |
ServeOptions |
The context, the handlers and the host-only extensions. |
Returns
Section titled “Returns”The connection, to send events and questions and to close it.
References
Section titled “References”PithyxError
Section titled “PithyxError”Re-exports PithyxError