Skip to content

@fkn/lib/packages

type AppConnectOptions = ConnectOptions & object;
optional payload?: unknown;

exposed to the package as ITS remote

optional raw?: boolean;

skip the osra handshake and hand back the untouched port - e.g. to transfer it into a worker and attach() there

optional signal?: AbortSignal;

type Connect = {
<T> (uri, options?): Promise<PackageConnection<T>>;
(uri, options): Promise<RawPackageConnection>;
};
<T>(uri, options?): Promise<PackageConnection<T>>;

T = unknown

string

ConnectOptions & object & object

Promise<PackageConnection<T>>

(uri, options): Promise<RawPackageConnection>;

string

ConnectOptions & object & object

Promise<RawPackageConnection>


type ConnectOptions = object;
optional protocol?: string;

opaque contract tag delivered to the package’s onConnect, e.g. ‘stub-source@1’


type ConnectPayload = (info) => unknown;

produces the payload exposed to a connecting app - called once per incoming connection

IncomingConnectionInfo

unknown


type IncomingConnection<T> = IncomingConnectionInfo & PackageConnection<T>;

T = unknown


type IncomingConnectionInfo = object;
from: string;

the connecting app’s identity: its package uri when it runs on a sandbox origin, else its page origin

name: string;

this package’s npm name

protocol: string | null;

the contract tag the app passed to connect(), e.g. ‘stub-source@1’

uri: string;

this package’s canonical uri per the connecting app’s install record, e.g. ‘npm:@banou/stub-source-example’

version: string;

the exact version this frame runs - the pin is encoded into the sandbox origin, immutable per version


type InstalledPackage = object;
installedAt: number;
name: string;
uri: string;
version: string;

type InstallOptions = object;
optional version?: string;

exact version to pin; defaults to the packument’s latest dist-tag


type PackageConnection<T> = object;

T = unknown

closed: Promise<void>;

settles when the package side of the connection dies (uninstall, reload, crash) - reconnect by calling connect() again

port: MessagePort;

the raw channel under remote, for direct messaging (osra envelopes ride it too - filter by your own message shape)

remote: Remote<T>;

the package’s exposed payload


type PackageQuery = object;
optional id?: string;

host app scope, e.g. ‘stub’ - becomes the keyword fkn-<type>--<id>

optional origin?: "npm";

package source; npm is the only origin implemented

optional size?: number;

result count, clamped to 1..100

optional text?: string;

free text mixed into the registry query

type: string;

package kind, e.g. ‘plugin’ - becomes the keyword fkn-type:<type>


type PackageResult = object;
description: string;
downloadsMonthly: number | null;
installed: boolean;

installed by the calling app

keywords: string[];
links: object;
optional homepage?: string;
optional npm?: string;
optional repository?: string;
name: string;
origin: "npm";
publisher: string | null;
uri: string;

canonical version-free uri, e.g. ‘npm:@banou/stub-plugin-foo’

version: string;

latest version per the search index - display only, install re-resolves from the packument


type PackagesError = Error & object;
code: PackagesErrorCode;

type PackagesErrorCode =
| "invalid"
| "not-installed"
| "unaddressable"
| "timeout"
| "unavailable"
| "denied";

type PickOptions = object;
optional multiple?: boolean;
optional title?: string;

untrusted, rendered as text in the picker header


type RawPackageConnection = Omit<PackageConnection<never>, "remote">;
const connect: Connect;

Connect to an installed package. Throws a PackagesError with code ‘not-installed’ when it is not.

function attach<T>(
port,
payload?,
options?): Promise<Remote<T>>;

Run this end of an already-brokered connection port, e.g. after transferring it into a worker.

T = unknown

MessagePort

unknown

AbortSignal

Promise<Remote<T>>


function install(uri, options?): Promise<InstalledPackage | null>;

Install a package for this app behind an FKN-rendered confirm. Resolves null when the user declines.

string

InstallOptions

Promise<InstalledPackage | null>


function list(): Promise<InstalledPackage[]>;

The packages installed by this app.

Promise<InstalledPackage[]>


function onConnect<T>(createPayload, handler?): object;

Serve connections from apps that installed this package. The first argument is called once per incoming connection with the connection info and returns the payload exposed to that app (its remote). The latest registration receives new connections; existing connections are unaffected.

T = unknown

ConnectPayload

(connection) => void

object

unsubscribe: () => void;

void


function pick(query, options?): Promise<PackageResult[]>;

FKN-rendered picker over the same search; resolves the user’s selection, already installed. [] on cancel.

PackageQuery

PickOptions

Promise<PackageResult[]>


function search(query): Promise<PackageResult[]>;

Search npm for FKN packages, e.g. search({ type: 'plugin', id: 'stub' }).

PackageQuery

Promise<PackageResult[]>


function uninstall(uri): Promise<void>;

Uninstall a package from this app; its frames and connections are torn down.

string

Promise<void>