You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit ebcbd34
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/content/1.guide/23.hub-ui-onboard.md
+20-9Lines changed: 20 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,12 +15,10 @@ A hub UI provider, its Vue runtime, and the devframes it mounts add tens of mega
15
15
16
16
The button sits at the bottom left, dimmed until hovered. It opens a panel with the product name and logo, one sentence, the exact command the install will run (for example `pnpm add -D @nuxt/devtools`), and three actions:
17
17
18
-
-**Install** runs the command in the project. The panel shows progress, then either the real dock replaces the button in place, or the panel asks for a restart.
18
+
-**Install** runs the command in the project after the developer allows it in the terminal (below). The panel shows progress, then either the real dock replaces the button in place, or the panel asks for a restart.
19
19
-**Hide for now** removes the button for the current browser tab.
20
20
-**Disable entirely** writes a state file so the host stops injecting the button on every later start.
21
21
22
-
Install and Disable entirely first ask for a 6-digit code that the dev server prints in the terminal (below).
23
-
24
22
The panel follows the shared design tokens, the host's `primaryColor`, and the user's hub color scheme, so the swap to the real dock looks like one product.
`packages` are package specs as the package manager accepts them. The package manager comes from the lockfile (`npm`, `pnpm`, `yarn`, `bun`, `deno`), `dev: true` adds `-D`, and `cwd` (default `process.cwd()`) is the project that receives the dependency. In a workspace, point `cwd` at the package that runs the dev server. The packages are fixed at creation.
45
43
46
-
## Confirm with the terminal code
44
+
## Confirm the install
45
+
46
+
Install changes `package.json` and the lockfile, and a dev server can be reachable from other devices. So each install that the panel asks for needs the developer's permission. By default, the onboarding asks in the terminal that runs the dev server:
47
+
48
+
1. The user clicks Install. The panel shows "Confirm in your terminal..." and its request waits.
49
+
2. The terminal prints [DF9005](/errors/DF9005). The developer types `y` and presses Enter to allow the install. Any other answer refuses it.
50
+
3. The install runs. After a refusal, the panel says that the dev server did not allow the install.
47
51
48
-
Install and Disable entirely change the project, and a dev server can listen on the network. So the onboarding accepts them only from a person who can read the terminal:
52
+
When stdin is not a TTY (CI, a detached container, a task runner that pipes stdin), nobody can answer. The onboarding then refuses at once with [DF9006](/errors/DF9006). Only one question is open at a time: more clicks while it is open share its answer. A `POST`from another origin is refused with `403` before any question.
49
53
50
-
1. The first `POST` from the panel has no code. The onboarding prints [DF9005](/errors/DF9005) with a 6-digit code and answers `401`.
51
-
2. The panel shows a field for the code. The user types it, and the panel sends it again in the `x-devframes-onboard-code` header.
52
-
3. After five wrong codes, both actions answer `429` with [DF9006](/errors/DF9006) until the dev server restarts.
54
+
To ask in another way, pass `confirm`. It gets the `packages`, the exact `command`, and the panel's `request`, and returns `true` to allow the install. For example, a Nuxt module can ask through `consola`:
55
+
56
+
```ts
57
+
import { consola } from'consola'
58
+
59
+
const onboarding =createOnboarding({
60
+
packages: ['@nuxt/devtools'],
61
+
confirm: ({ command }) =>consola.prompt(`Run \`${command.join('')}\` for the browser that asked?`, { type: 'confirm' }),
62
+
})
63
+
```
53
64
54
-
The code stays the same for the life of the process, so Retry after a failed install does not ask again. A `POST` from another origin is also refused with `403`. The host has nothing to configure.
65
+
Disable entirely does not ask. It changes only the state file in `node_modules/.devframe`.
description: 'A browser asked to {action}. To allow it, enter this code in the panel: {code}'
2
+
title: 'DF9005: Confirm the Install'
3
+
description: 'A browser asked to run `{command}`. Type y and press Enter to allow it.'
4
4
---
5
5
6
6
## Message
7
7
8
-
> A browser asked to `{action}`. To allow it, enter this code in the panel: `{code}`
8
+
> A browser asked to run `{command}`. Type y and press Enter to allow it.
9
9
10
10
## Cause
11
11
12
-
Install and Disable change the project, and a dev server can listen on the network. So the onboarding panel must send a 6-digit code that only the terminal shows. A request to `POST <base>__onboard/install`or `POST <base>__onboard/disable` came without the `x-devframes-onboard-code` header, and `createOnboarding()`printed the code. The code stays the same until the process exits.
12
+
Install changes `package.json` and the lockfile, and a dev server can be reachable from other devices. So each install that the panel asks for needs the developer's permission. The panel's `POST <base>__onboard/install`waits until you answer. Without a `confirm` option, `createOnboarding()`asks in the terminal that runs the dev server.
13
13
14
14
## Fix
15
15
16
-
If you clicked Install or Disable entirely, type the code into the panel. If you did not, another device or page can reach this dev server. Do not enter the code anywhere, and bind the dev server to `localhost`.
16
+
If you clicked Install, type `y` and press Enter. Any other answer refuses the install, and the panel tells the user. If you did not click Install, press Enter. Another device or page can reach this dev server, so bind it to `localhost`.
17
+
18
+
To ask in another way, for example with your own logger, pass a `confirm` function to `createOnboarding()`.
17
19
18
20
## Source
19
21
20
-
-[`packages/hub-ui-onboard/src/index.ts`](https://github.com/devframes/devframe/blob/main/packages/hub-ui-onboard/src/index.ts): `authorize()` prints this and answers with status 401 when the request has no code.
22
+
-[`packages/hub-ui-onboard/src/terminal-confirm.ts`](https://github.com/devframes/devframe/blob/main/packages/hub-ui-onboard/src/terminal-confirm.ts): `confirmInTerminal()` prints this, then reads one line from stdin.
description: 'Five wrong onboarding codes were entered. Install and Disable are blocked until the dev server restarts.'
2
+
title: 'DF9006: No Terminal to Confirm the Install'
3
+
description: 'A browser asked to run `{command}`, but no interactive terminal can confirm it. The install was refused.'
4
4
---
5
5
6
6
## Message
7
7
8
-
> Five wrong onboarding codes were entered. Install and Disable are blocked until the dev server restarts.
8
+
> A browser asked to run `{command}`, but no interactive terminal can confirm it. The install was refused.
9
9
10
10
## Cause
11
11
12
-
Install and Disable need the code that [DF9005](/errors/DF9005) prints. After five wrong codes, `createOnboarding()`refuses both actions for the rest of the process, so nobody can guess the code.
12
+
Each install that the panel asks for needs the developer's permission ([DF9005](/errors/DF9005)). Without a `confirm` option, `createOnboarding()`asks in the terminal. Here stdin is not a TTY, so nobody can answer. This happens in CI, in a detached container, or when a task runner pipes stdin. The install is refused at once, and the panel tells the user.
13
13
14
14
## Fix
15
15
16
-
Restart the dev server. It prints a new code the next time you click Install or Disable entirely. If you did not enter the wrong codes, another device or page can reach this dev server: bind it to `localhost`. You can also run the install command from the panel in a terminal.
16
+
Run the command from the panel in a terminal yourself. Or pass a `confirm` function to `createOnboarding()` that asks in another way.
17
17
18
18
## Source
19
19
20
-
-[`packages/hub-ui-onboard/src/index.ts`](https://github.com/devframes/devframe/blob/main/packages/hub-ui-onboard/src/index.ts): `authorize()` reports this on the fifth wrong code, then answers each later Install or Disable with status 429 and this code.
20
+
-[`packages/hub-ui-onboard/src/terminal-confirm.ts`](https://github.com/devframes/devframe/blob/main/packages/hub-ui-onboard/src/terminal-confirm.ts): `confirmInTerminal()` reports this and returns `false` when stdin is not a TTY.
Copy file name to clipboardExpand all lines: docs/content/8.references/6.hub-api.md
+4-5Lines changed: 4 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,17 +96,16 @@ What `createOnboarding()` from `@devframes/hub-ui-onboard` accepts and serves: [
96
96
|`stateDir`|`<cwd>/node_modules/.devframe`| Directory of the `hub-ui-onboard.json` state file |
97
97
|`dev`|`true`| Install as a devDependency |
98
98
|`branding`|`{}`|`productName` (default `Devframes`), `logo` (URL or `{ light, dark }`), `primaryColor`|
99
-
|`messages`| derived from `productName`| Overrides for `title`, `description`, `install`, `code`, `wrongCode`, `hide`, `disable`, `installing`, `restart`, `retry`|
99
+
|`messages`| derived from `productName`| Overrides for `title`, `description`, `install`, `confirming`, `refused`, `hide`, `disable`, `installing`, `restart`, `retry`|
100
100
|`onInstalled`| none | Runs after a verified install, or on the first request when the packages already exist; a returned handler takes over `base`|
101
+
|`confirm`|`y/N` in the terminal | Gets `{ packages, command, request }` before each install the panel asks for; return `true` to allow it. Refuses when stdin is not a TTY |
101
102
102
103
| Route | Serves |
103
104
| --- | --- |
104
105
|`GET <base>embedded.js`| the floating button, a self-contained ES module |
|`POST <base>__onboard/install`| starts the install (`202`), with the terminal code only |
107
-
|`POST <base>__onboard/disable`| writes the state file (`204`), with the terminal code only |
108
-
109
-
Both `POST` routes answer `403` to another origin. Without the `x-devframes-onboard-code` header, they print the code ([DF9005](/errors/DF9005)) and answer `401`. A wrong code also gets `401`. After five wrong codes, they answer `429` with [DF9006](/errors/DF9006) until the process restarts.
107
+
|`POST <base>__onboard/install`| waits for `confirm`, then starts the install (`202`) or refuses it (`403`); same-origin only |
108
+
|`POST <base>__onboard/disable`| writes the state file (`204`), same-origin only |
Copy file name to clipboardExpand all lines: examples/hub-onboard-vite/README.md
+2-4Lines changed: 2 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,14 +6,12 @@ A Vite host that ships only `@devframes/hub-ui-onboard` (about 20 kB in the brow
6
6
pnpm --filter hub-onboard-vite dev
7
7
```
8
8
9
-
Open the printed URL. The button at the bottom left opens a panel with three actions:
9
+
Open the printed URL. The button at the bottom left opens a panel with two actions:
10
10
11
-
- Install runs `pnpm add -D @devframes/hub @devframes/hub-ui @devframes/plugin-git` in this directory. When it finishes, the host starts the real hub on `/__devframes/` in the same process and the button swaps itself for the floating dock.
11
+
- Install asks you to type `y` in the terminal that runs Vite, then runs `pnpm add -D @devframes/hub @devframes/hub-ui @devframes/plugin-git` in this directory. When it finishes, the host starts the real hub on `/__devframes/` in the same process and the button swaps itself for the floating dock.
12
12
- Hide for now hides the button for this browser tab.
13
13
- Disable entirely writes `node_modules/.devframe/hub-ui-onboard.json`. The host reads `onboarding.disabled` on the next start and injects no script.
14
14
15
-
Install and Disable entirely ask for the 6-digit code that the dev server prints in the terminal (`DF9005`).
16
-
17
15
When the three packages are already installed, the button never shows: the host's `onInstalled` runs on the first request and the real dock appears directly.
18
16
19
17
Install changes this example's `package.json` and the lockfile. Run `git checkout -- examples/hub-onboard-vite pnpm-lock.yaml` and delete the state file to reset the demo.
Copy file name to clipboardExpand all lines: packages/hub-ui-onboard/playground/index.html
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -14,14 +14,15 @@
14
14
</head>
15
15
<body>
16
16
<h1>hub-ui-onboard</h1>
17
-
<p>The floating button loads from <code>src/client</code> and talks to a mock <code>__onboard</code> API. When Install or Disable asks for the terminal code, enter <code>123456</code>.</p>
17
+
<p>The floating button loads from <code>src/client</code> and talks to a mock <code>__onboard</code> API.</p>
0 commit comments