@appos.space/plugin-types
v3.0.2
Published
TypeScript type definitions for the AppOS Plugin API
Maintainers
Readme
@appos.space/plugin-types
TypeScript type definitions for the AppOS Plugin API.
Declaration-only package — zero runtime, zero bundle impact. Gives you full
autocomplete and type checking for all 43 plugin namespaces and the full
PermissionScope union when authoring plugins for AppOS.
Install
npm install --save-dev @appos.space/plugin-typesUsage
Import the types you need (the main entry ships module exports only; the ONE exception is the opt-in globals subpath — see Host-injected globals below):
import type {
PluginContext,
PluginManifest,
ViewDescriptor,
PermissionScope,
} from "@appos.space/plugin-types";
export async function activate(ctx: PluginContext) {
const dir = await ctx.fileOps.getActiveDirectory();
ctx.ui.showNotification({ message: `Hello from ${dir}` });
}Host-injected globals (opt-in)
AppOS hosts inject a Foundation-bridged URL constructor into the
JavaScriptCore plugin runtime (targeted for host 1.1.0). The matching
ambient declaration ships as a SEPARATE opt-in subpath,
@appos.space/plugin-types/globals, so nothing global leaks into projects
that don't reference it. Opt in from your plugin entry file:
/// <reference types="@appos.space/plugin-types/globals" />or in tsconfig.json:
{ "compilerOptions": { "types": ["@appos.space/plugin-types/globals"] } }The global is typed URLConstructor | undefined — older hosts, menu-bar
JSContext pools, and the appos.jsc.urlGlobal.disabled kill switch all
leave it undefined. ALWAYS guard before use. Pinning your manifest's
minHostVersion to an injecting host release removes only the older-host
reason for absence — it does not override the kill switch or the menu-bar
limitation, so unguarded use can still crash at runtime:
if (typeof URL === "function" && URL.canParse(raw)) {
const u = new URL(raw);
// u.hostname parses identically to the host's own security validators
}Notes:
- Foundation (RFC 3986) semantics, not a WHATWG polyfill. The pinned
divergences are documented in the subpath's docblock: default ports
retained in
href/port, empty path stays"", out-of-range ports accepted,hostnamelowercased with IPv6 unbracketed (host/originre-bracket). Pre-encoded query values round-trip verbatim on href (%3Astays%3A) — the%3A→%253Adouble-encode seen via Foundation'sURLComponents.queryItemsdoes not apply to this API. url.searchParamsis NOT in the v1 subset — the type omits it and the runtime getter throws aTypeError; parseurl.searchmanually.URL.parseis likewise absent, and all accessors are readonly.- Reference the subpath only from a DOM-free tsconfig (e.g.
"lib": ["ES2020"]) — never from webview code compiled againstlib.dom, which already has its ownURL. The two declarations conflict, but don't rely on that as a safeguard: withskipLibCheckenabled (the default in most scaffolds) TypeScript suppresses declaration-file conflicts and silently merges the interfaces, so browser-only members (searchParams, mutable accessors, unguarded construction) can type-check against the narrower JSC runtime. The DOM-freelibis the only reliable isolation.
What's included
- Core —
PluginContext,PluginManifest, activation lifecycle - Views —
ViewDescriptorunion for declarative UI - Namespaces — typed APIs for
fileOps,ui,shell,network,storage,actions, and 37 more (the 22 host-core namespaces plus the 21 core-plugin namespaces) - Permissions —
PermissionScope: the 135 canonical permission scopes you can request inplugin.json, plus the dynamicoauth.${string}family for provider-specific OAuth scopes (e.g.oauth.github), plus 5 deprecated legacy aliases kept in the type union for compile-time compatibility only — of those, onlynetwork.fetchis recognized by the host (normalized tonetwork.outbound);network,smartFolders, andwebviewhave no host-side entry, andshell.uncontainedis never declarable (the uncontained shell tier is inferred fromfilesystem.readAll) - Colors / Fonts / Icons — design tokens matching the host app
Version
Tracks the plugin API version — the package's major.minor matches the plugin API's major.minor (e.g. 3.0.x of this package ↔ plugin API 3.0.x).
Related packages
@appos.space/view-builders— ergonomicvstack()/listItem()/section()helpers forViewDescriptor@appos.space/plugin-utils— shared pure utilities (path conversion, formatting, action routing)
License
MIT © InstantlyEasy
