@fkn/lib/packages
Type Aliases
Section titled “Type Aliases”AppConnectOptions
Section titled “AppConnectOptions”type AppConnectOptions = ConnectOptions & object;Type Declaration
Section titled “Type Declaration”payload?
Section titled “payload?”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
signal?
Section titled “signal?”optional signal?: AbortSignal;Connect
Section titled “Connect”type Connect = {<T> (uri, options?): Promise<PackageConnection<T>>; (uri, options): Promise<RawPackageConnection>;};Call Signature
Section titled “Call Signature”<T>(uri, options?): Promise<PackageConnection<T>>;Type Parameters
Section titled “Type Parameters”T = unknown
Parameters
Section titled “Parameters”string
options?
Section titled “options?”ConnectOptions & object & object
Returns
Section titled “Returns”Call Signature
Section titled “Call Signature”(uri, options): Promise<RawPackageConnection>;Parameters
Section titled “Parameters”string
options
Section titled “options”ConnectOptions & object & object
Returns
Section titled “Returns”ConnectOptions
Section titled “ConnectOptions”type ConnectOptions = object;Properties
Section titled “Properties”protocol?
Section titled “protocol?”optional protocol?: string;opaque contract tag delivered to the package’s onConnect, e.g. ‘stub-source@1’
ConnectPayload
Section titled “ConnectPayload”type ConnectPayload = (info) => unknown;produces the payload exposed to a connecting app - called once per incoming connection
Parameters
Section titled “Parameters”Returns
Section titled “Returns”unknown
IncomingConnection
Section titled “IncomingConnection”type IncomingConnection<T> = IncomingConnectionInfo & PackageConnection<T>;Type Parameters
Section titled “Type Parameters”T = unknown
IncomingConnectionInfo
Section titled “IncomingConnectionInfo”type IncomingConnectionInfo = object;Properties
Section titled “Properties”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
Section titled “protocol”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
Section titled “version”version: string;the exact version this frame runs - the pin is encoded into the sandbox origin, immutable per version
InstalledPackage
Section titled “InstalledPackage”type InstalledPackage = object;Properties
Section titled “Properties”installedAt
Section titled “installedAt”installedAt: number;name: string;uri: string;version
Section titled “version”version: string;InstallOptions
Section titled “InstallOptions”type InstallOptions = object;Properties
Section titled “Properties”version?
Section titled “version?”optional version?: string;exact version to pin; defaults to the packument’s latest dist-tag
PackageConnection
Section titled “PackageConnection”type PackageConnection<T> = object;Type Parameters
Section titled “Type Parameters”T = unknown
Properties
Section titled “Properties”closed
Section titled “closed”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
Section titled “remote”remote: Remote<T>;the package’s exposed payload
PackageQuery
Section titled “PackageQuery”type PackageQuery = object;Properties
Section titled “Properties”optional id?: string;host app scope, e.g. ‘stub’ - becomes the keyword fkn-<type>--<id>
origin?
Section titled “origin?”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>
PackageResult
Section titled “PackageResult”type PackageResult = object;Properties
Section titled “Properties”description
Section titled “description”description: string;downloadsMonthly
Section titled “downloadsMonthly”downloadsMonthly: number | null;installed
Section titled “installed”installed: boolean;installed by the calling app
keywords
Section titled “keywords”keywords: string[];links: object;homepage?
Section titled “homepage?”optional homepage?: string;optional npm?: string;repository?
Section titled “repository?”optional repository?: string;name: string;origin
Section titled “origin”origin: "npm";publisher
Section titled “publisher”publisher: string | null;uri: string;canonical version-free uri, e.g. ‘npm:@banou/stub-plugin-foo’
version
Section titled “version”version: string;latest version per the search index - display only, install re-resolves from the packument
PackagesError
Section titled “PackagesError”type PackagesError = Error & object;Type Declaration
Section titled “Type Declaration”code: PackagesErrorCode;PackagesErrorCode
Section titled “PackagesErrorCode”type PackagesErrorCode = | "invalid" | "not-installed" | "unaddressable" | "timeout" | "unavailable" | "denied";PickOptions
Section titled “PickOptions”type PickOptions = object;Properties
Section titled “Properties”multiple?
Section titled “multiple?”optional multiple?: boolean;title?
Section titled “title?”optional title?: string;untrusted, rendered as text in the picker header
RawPackageConnection
Section titled “RawPackageConnection”type RawPackageConnection = Omit<PackageConnection<never>, "remote">;Variables
Section titled “Variables”connect
Section titled “connect”const connect: Connect;Connect to an installed package. Throws a PackagesError with code ‘not-installed’ when it is not.
Functions
Section titled “Functions”attach()
Section titled “attach()”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.
Type Parameters
Section titled “Type Parameters”T = unknown
Parameters
Section titled “Parameters”MessagePort
payload?
Section titled “payload?”unknown
options?
Section titled “options?”signal?
Section titled “signal?”AbortSignal
Returns
Section titled “Returns”Promise<Remote<T>>
install()
Section titled “install()”function install(uri, options?): Promise<InstalledPackage | null>;Install a package for this app behind an FKN-rendered confirm. Resolves null when the user declines.
Parameters
Section titled “Parameters”string
options?
Section titled “options?”Returns
Section titled “Returns”Promise<InstalledPackage | null>
list()
Section titled “list()”function list(): Promise<InstalledPackage[]>;The packages installed by this app.
Returns
Section titled “Returns”onConnect()
Section titled “onConnect()”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.
Type Parameters
Section titled “Type Parameters”T = unknown
Parameters
Section titled “Parameters”createPayload
Section titled “createPayload”handler?
Section titled “handler?”(connection) => void
Returns
Section titled “Returns”object
unsubscribe
Section titled “unsubscribe”unsubscribe: () => void;Returns
Section titled “Returns”void
pick()
Section titled “pick()”function pick(query, options?): Promise<PackageResult[]>;FKN-rendered picker over the same search; resolves the user’s selection, already installed. [] on cancel.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”search()
Section titled “search()”function search(query): Promise<PackageResult[]>;Search npm for FKN packages, e.g. search({ type: 'plugin', id: 'stub' }).
Parameters
Section titled “Parameters”Returns
Section titled “Returns”uninstall()
Section titled “uninstall()”function uninstall(uri): Promise<void>;Uninstall a package from this app; its frames and connections are torn down.
Parameters
Section titled “Parameters”string
Returns
Section titled “Returns”Promise<void>