@tailor-platform/sdk-plugin-studio
v0.1.0
Published
Tailor CLI plugin providing the `tailor studio` command (local web UI shell for CLI plugins)
Maintainers
Keywords
Readme
@tailor-platform/sdk-plugin-studio
Tailor CLI plugin that provides tailor studio: a local web UI shell, built with AppShell, that hosts the UIs of other CLI plugins on a single port.
[!NOTE] This package is a CLI plugin: it ships an external
tailor-studioexecutable that the Tailor CLI dispatches to when you runtailor studio. It is a beta feature.
Installation
npm install -D @tailor-platform/sdk-plugin-studioUsage
# Serve the UI on port 7777 (or the next free port) and print its URL
tailor studio
# Prefer another port and open the browser
tailor studio --port 8080 --openThe server listens on 127.0.0.1 only. It is meant for a machine you use alone: any other user or process on the same machine can reach the port, and what a tab does runs with your stored login. The checks on each request keep other web pages in your browser out; they do not authenticate a client on the same machine. The default tab is the TailorDB ERD viewer from @tailor-platform/sdk-plugin-tailordb-erd; without that plugin the tab shows how to install it.
Profile
The header at the top of the page shows the profile (and the workspace it points to) that every tab works against, and switches it. The profiles are the ones of tailor profile list. --profile (or TAILOR_PLATFORM_PROFILE) gives the first selection; a profile that does not exist stops the start. The "New profile" button next to the selector creates a profile (name, a user logged in with tailor login, a workspace that user can see, and read/write permission) and selects it. The platform is the one the environment names when tailor studio starts (TAILOR_PLATFORM_URL, TAILOR_PLATFORM_OAUTH2_CLIENT_ID, TAILOR_PLATFORM_CONSOLE_URL): only users logged in on it are offered, their workspaces are read from it, and the new profile stores it. When the environment changes any of them, the header shows a platform: <URL> badge (hover for all the values) and the New profile dialog lists them. The choice is remembered per project in node_modules/.cache/tailor-studio/, so the next tailor studio in the same project starts with it (--profile wins when given). The header turns gray while no profile is selected.
Mounting a plugin's UI
A plugin that provides a tab declares its UI in package.json. The shell currently has one built-in tab, the ERD viewer; discovering the tabs of other plugins is not implemented yet, so this is the contract a plugin's UI has to follow:
{
"tailorUi": { "id": "my-plugin", "title": "My plugin", "kind": "module", "entry": "./dist/ui.js" }
}entry must have a default export of type UiHandler, a Web-standard (request, context) => Response:
import { selectionArgs, type UiHandler } from "@tailor-platform/sdk-plugin-studio";
const handler: UiHandler = (request, { basePath, getSelection, onSelectionChange }) =>
new Response("...");
export default handler;- The shell serves the handler under
/plugins/<id>/. The request URL it receives has that prefix removed, andbasePathis the prefix. Reference assets and APIs with relative URLs. - The shell checks every request before it reaches a handler. A request a browser marks
Sec-Fetch-Site: cross-siteorsame-siteis rejected, so another page cannot make the browser call a handler; opening the UI from the address bar, a bookmark or--openis unaffected. A request other thanGET/HEADmust be markedSec-Fetch-Site: same-origin, and anOriginit carries must be a local one. A browser sets that mark itself, so a page of another site cannot make it write:fetchfrom the plugin's page works without any extra header, and a client that does not set the mark, such ascurl, is rejected. getSelection()returns the profile / workspace chosen in the bar,{ profile?, workspaceId? }, as of that call.selectionArgs(getSelection())turns it intotailoroptions (--profile=<name>; the workspace is the one the profile points to when the command runs) and is empty while nothing is selected, in which case the tab should ask the user to choose one in the bar.- A
tailorcommand a tab starts for the selection must run withselectionEnv(getSelection())as its environment.tailor studiostarts with the startup user'sTAILOR_PLATFORM_TOKEN, the startup profile'sTAILOR_PLATFORM_URLandTAILOR_PLATFORM_OAUTH2_CLIENT_ID, and its workspace inTAILOR_PLATFORM_WORKSPACE_ID. The CLI prefers the token and the workspace to--profileand uses the platform for what the profile does not store, so withoutselectionEnva command for another profile runs with the wrong user's credentials, on the wrong platform or in the wrong workspace. While nothing is selected the four are kept. onSelectionChange(listener)callslistenerwhenever the choice changes, from any open window, and returns the function that stops it. A listener that throws is reported in the server log and does not stop the other listeners or fail the change. A tab that keeps work running against the selection can stop it there instead of pollinggetSelection().- A handler may return a streaming
text/event-streamresponse. idis the tab's route (/<id>), soapi,pluginsandassetsare rejected.- Only
kind: "module"is supported.kind: "process"is reserved for plugins that run as a separate process and is rejected for now.
