@jskit-ai/agent-docs 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DISTR_AGENT.md +25 -0
- package/guide/agent/app-extras/assistant.md +636 -0
- package/guide/agent/app-extras/realtime.md +223 -0
- package/guide/agent/app-setup/a-more-interesting-shell.md +643 -0
- package/guide/agent/app-setup/authentication.md +948 -0
- package/guide/agent/app-setup/console.md +316 -0
- package/guide/agent/app-setup/database-layer.md +775 -0
- package/guide/agent/app-setup/initial-scaffolding.md +714 -0
- package/guide/agent/app-setup/multi-homing.md +655 -0
- package/guide/agent/app-setup/users.md +355 -0
- package/guide/agent/app-setup/working-with-the-jskit-cli.md +983 -0
- package/guide/agent/generators/advanced-cruds.md +923 -0
- package/guide/agent/generators/crud-generators.md +556 -0
- package/guide/agent/generators/intro.md +63 -0
- package/guide/agent/generators/ui-generators.md +648 -0
- package/guide/agent/index.md +39 -0
- package/guide/human/app-extras/assistant.md +695 -0
- package/guide/human/app-extras/realtime.md +270 -0
- package/guide/human/app-setup/a-more-interesting-shell.md +734 -0
- package/guide/human/app-setup/authentication.md +963 -0
- package/guide/human/app-setup/console.md +352 -0
- package/guide/human/app-setup/database-layer.md +822 -0
- package/guide/human/app-setup/initial-scaffolding.md +738 -0
- package/guide/human/app-setup/multi-homing.md +795 -0
- package/guide/human/app-setup/users.md +404 -0
- package/guide/human/app-setup/working-with-the-jskit-cli.md +997 -0
- package/guide/human/generators/advanced-cruds.md +923 -0
- package/guide/human/generators/crud-generators.md +556 -0
- package/guide/human/generators/intro.md +109 -0
- package/guide/human/generators/ui-generators.md +665 -0
- package/guide/human/index.md +39 -0
- package/package.json +28 -0
- package/reference/autogen/KERNEL_MAP.md +536 -0
- package/reference/autogen/README.md +44 -0
- package/reference/autogen/packages/agent-docs.md +13 -0
- package/reference/autogen/packages/assistant-core.md +310 -0
- package/reference/autogen/packages/assistant-runtime.md +219 -0
- package/reference/autogen/packages/assistant.md +73 -0
- package/reference/autogen/packages/auth-core.md +352 -0
- package/reference/autogen/packages/auth-provider-supabase-core.md +223 -0
- package/reference/autogen/packages/auth-web.md +267 -0
- package/reference/autogen/packages/console-core.md +116 -0
- package/reference/autogen/packages/console-web.md +37 -0
- package/reference/autogen/packages/crud-core.md +283 -0
- package/reference/autogen/packages/crud-server-generator.md +220 -0
- package/reference/autogen/packages/crud-ui-generator.md +154 -0
- package/reference/autogen/packages/database-runtime-mysql.md +61 -0
- package/reference/autogen/packages/database-runtime-postgres.md +39 -0
- package/reference/autogen/packages/database-runtime.md +216 -0
- package/reference/autogen/packages/http-runtime.md +213 -0
- package/reference/autogen/packages/kernel.md +1350 -0
- package/reference/autogen/packages/realtime.md +95 -0
- package/reference/autogen/packages/shell-web.md +349 -0
- package/reference/autogen/packages/storage-runtime.md +39 -0
- package/reference/autogen/packages/ui-generator.md +101 -0
- package/reference/autogen/packages/uploads-image-web.md +76 -0
- package/reference/autogen/packages/uploads-runtime.md +85 -0
- package/reference/autogen/packages/users-core.md +307 -0
- package/reference/autogen/packages/users-web.md +473 -0
- package/reference/autogen/packages/workspaces-core.md +415 -0
- package/reference/autogen/packages/workspaces-web.md +372 -0
- package/reference/autogen/tooling/config-eslint.md +52 -0
- package/reference/autogen/tooling/create-app.md +194 -0
- package/reference/autogen/tooling/jskit-catalog.md +27 -0
- package/reference/autogen/tooling/jskit-cli.md +624 -0
- package/reference/autogen/tooling/test-support.md +27 -0
- package/reference/autogen/tooling/testUtils.md +31 -0
- package/templates/APP_BLUEPRINT.md +57 -0
- package/workflow/app-state.md +33 -0
- package/workflow/bootstrap.md +24 -0
- package/workflow/feature-delivery.md +21 -0
- package/workflow/review.md +22 -0
- package/workflow/scoping.md +26 -0
|
@@ -0,0 +1,655 @@
|
|
|
1
|
+
<!-- Generated by `npm run agent-docs:build` from `docs/guide/app-setup/multi-homing.md`. Do not edit manually. -->
|
|
2
|
+
|
|
3
|
+
# Multi-homing
|
|
4
|
+
|
|
5
|
+
Up to this point, the app has had several surfaces, but none of them were workspace-dependent. `home`, `auth`, `account`, and `console` all live outside any workspace slug.
|
|
6
|
+
|
|
7
|
+
This chapter changes that. We turn the app into a workspace-aware application and install the packages that add the first real workspace surfaces.
|
|
8
|
+
|
|
9
|
+
If you are rebuilding this chapter from scratch, the cleanest setup is to start with a workspace-capable tenancy mode from day 0. If you are literally continuing from the previous chapter, you can still move the existing app from `none` to `personal`, but that retrofit has to be done in the right order.
|
|
10
|
+
|
|
11
|
+
## Tenancy modes
|
|
12
|
+
|
|
13
|
+
JSKIT currently accepts three tenancy modes:
|
|
14
|
+
|
|
15
|
+
- `none`
|
|
16
|
+
- no workspace routing
|
|
17
|
+
- no `/w/[workspaceSlug]` surfaces
|
|
18
|
+
- useful for a purely global app with no workspace concept
|
|
19
|
+
- `personal`
|
|
20
|
+
- workspace routing is enabled
|
|
21
|
+
- each user gets one auto-provisioned personal workspace
|
|
22
|
+
- the workspace slug is derived from the user's identity and treated as immutable
|
|
23
|
+
- creating additional workspaces is off by default
|
|
24
|
+
- `workspaces`
|
|
25
|
+
- workspace routing is enabled
|
|
26
|
+
- users can belong to multiple named workspaces
|
|
27
|
+
- workspace slugs are user-selected rather than derived from the username
|
|
28
|
+
- auto-provisioning is off by default, and self-creation is a separate policy choice
|
|
29
|
+
|
|
30
|
+
Both `personal` and `workspaces` are workspace-capable modes, so they allow the workspace package descriptors to install the full workspace scaffold.
|
|
31
|
+
|
|
32
|
+
This chapter teaches `personal`, not `workspaces`.
|
|
33
|
+
|
|
34
|
+
That is deliberate. `personal` gives the guide a much better first-run experience because the first workspace is auto-provisioned for the user. The app still becomes multi-homing-capable, because invitations and memberships can still put one user in several workspaces at once. The `personal` part only changes how the first workspace is provisioned and how its slug policy works.
|
|
35
|
+
|
|
36
|
+
## Installing the workspace packages
|
|
37
|
+
|
|
38
|
+
If your app is already on `tenancyMode = "personal"`, run:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
npx jskit add package workspaces-core
|
|
42
|
+
npm install
|
|
43
|
+
npx jskit add package workspaces-web
|
|
44
|
+
npm install
|
|
45
|
+
npm run db:migrate
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
`workspaces-core` adds the server-side workspace runtime and schema migrations. `workspaces-web` adds the workspace-facing client surfaces, shell placements, and app-owned route files.
|
|
49
|
+
|
|
50
|
+
If you want to inspect that package before installing it, this is a very good moment to use the CLI chapter's inspection command:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
npx jskit show @jskit-ai/workspaces-web --details
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
That output makes the package feel much less mysterious, because it shows the exact workspace shell contributions, settings outlets, client tokens, app-owned file writes, and capability requirements before you mutate the app.
|
|
57
|
+
|
|
58
|
+
## What changes now
|
|
59
|
+
|
|
60
|
+
This chapter is where the app stops being a collection of global surfaces and starts supporting workspace-dependent ones.
|
|
61
|
+
|
|
62
|
+
### Two new workspace surfaces appear
|
|
63
|
+
|
|
64
|
+
After the install, the app gains:
|
|
65
|
+
|
|
66
|
+
- an `app` surface rooted at `/w/[workspaceSlug]`
|
|
67
|
+
- an `admin` surface rooted at `/w/[workspaceSlug]/admin`
|
|
68
|
+
|
|
69
|
+
These are real surfaces, not only pages.
|
|
70
|
+
|
|
71
|
+
- `app` is the generic workspace surface that normal authenticated workspace members can use
|
|
72
|
+
- `admin` is the richer workspace administration surface
|
|
73
|
+
|
|
74
|
+
That distinction matters.
|
|
75
|
+
|
|
76
|
+
The `app` surface is the "normal" workspace area. It is where you would usually put the main member-facing experience for that workspace: dashboards, documents, tasks, project views, customer-facing content, or whatever the ordinary in-workspace product actually is.
|
|
77
|
+
|
|
78
|
+
The `admin` surface is where the workspace is managed. It is the natural place for things like:
|
|
79
|
+
|
|
80
|
+
- inviting other users into the workspace
|
|
81
|
+
- managing members and roles
|
|
82
|
+
- editing workspace settings
|
|
83
|
+
- running workspace-specific admin tools
|
|
84
|
+
|
|
85
|
+
So `admin` is not just "another page." It is the surface where the workspace itself is configured and operated.
|
|
86
|
+
|
|
87
|
+
There is also no rule that says every app must use these two surfaces in the same way.
|
|
88
|
+
|
|
89
|
+
- In one app, `app` could be the real product and `admin` could be the backend for managing it.
|
|
90
|
+
- In another app, `admin` might be where most of the real work happens, while `app` stays minimal or even almost empty.
|
|
91
|
+
- In a storefront-style app, `app` could be the workspace's visible shop area and `admin` could be the merchant backend.
|
|
92
|
+
|
|
93
|
+
The important point is not the label. The important point is the split:
|
|
94
|
+
|
|
95
|
+
- `app` is the general workspace-facing surface
|
|
96
|
+
- `admin` is the management and control surface for that workspace
|
|
97
|
+
|
|
98
|
+
That is why this chapter feels larger than the previous ones. It is not just adding another route. It is adding a new routing topology.
|
|
99
|
+
|
|
100
|
+
### The shell and account surface gain workspace-aware controls
|
|
101
|
+
|
|
102
|
+
The placement registry now grows a workspace selector in the top-left of the shell, a pending-invites cue in the top-right area, and workspace tools in the admin shell. The workspaces package also plugs an `Invites` section into the existing `/account` settings screen through the account-settings extension seam that `users-web` exposes.
|
|
103
|
+
|
|
104
|
+
That means the shell itself starts adapting to workspace context.
|
|
105
|
+
|
|
106
|
+
- on any authenticated surface, the shell can now expose a workspace selector
|
|
107
|
+
- signed-in users can now see a pending-invites cue without `users-web` owning that workspace feature
|
|
108
|
+
- on admin workspace surfaces, the shell can also expose workspace-specific tools and settings
|
|
109
|
+
|
|
110
|
+
This is the first time the guide shows the shell reacting not just to authentication state, but to workspace state as well.
|
|
111
|
+
|
|
112
|
+
### The database schema grows real multi-workspace tables
|
|
113
|
+
|
|
114
|
+
`workspaces-core` adds the schema needed for:
|
|
115
|
+
|
|
116
|
+
- workspaces
|
|
117
|
+
- workspace memberships
|
|
118
|
+
- workspace settings
|
|
119
|
+
- workspace invites
|
|
120
|
+
|
|
121
|
+
That is why `npm run db:migrate` is required again in this chapter. The workspace runtime is not only client-side routing. It is persistent tenancy data.
|
|
122
|
+
|
|
123
|
+
### Existing surfaces do not disappear
|
|
124
|
+
|
|
125
|
+
This is also important to notice:
|
|
126
|
+
|
|
127
|
+
- `home` still exists
|
|
128
|
+
- `auth` still exists
|
|
129
|
+
- `account` still exists
|
|
130
|
+
- `console` still exists
|
|
131
|
+
|
|
132
|
+
The new workspace surfaces are added on top of the existing app, not instead of it.
|
|
133
|
+
|
|
134
|
+
That is exactly what multi-homing should feel like. The app now has both:
|
|
135
|
+
|
|
136
|
+
- global surfaces
|
|
137
|
+
- workspace-scoped surfaces
|
|
138
|
+
|
|
139
|
+
## What to look at in the browser
|
|
140
|
+
|
|
141
|
+
Start both processes again:
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
npm run dev
|
|
145
|
+
npm run server
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
After you sign in, the app now has the routing structure needed for workspace-aware paths such as:
|
|
149
|
+
|
|
150
|
+
```text
|
|
151
|
+
/w/your-personal-slug
|
|
152
|
+
/w/your-personal-slug/admin
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
In `personal` mode, the first workspace is auto-provisioned for the signed-in user, so you should have a real workspace route to open immediately after login. Later, if the same user is invited into another workspace, routes such as `/w/acme` can exist alongside that personal workspace too.
|
|
156
|
+
|
|
157
|
+
At this stage of the guide, the starter workspace pages are still intentionally simple. That is helpful. It lets you see the new routing and shell topology clearly before later chapters add real modules inside those surfaces.
|
|
158
|
+
|
|
159
|
+
The most important new visible ideas are:
|
|
160
|
+
|
|
161
|
+
- a workspace slug now appears in the route
|
|
162
|
+
- the shell can expose workspace selection and workspace tools
|
|
163
|
+
- workspace-dependent surfaces can show a dedicated unavailable-state card when the requested workspace cannot be resolved
|
|
164
|
+
|
|
165
|
+
First, even the old global `/home` surface now reacts to workspace state. The selector in the top-left and the invites cue in the top-right come from placement entries and workspace bootstrap context, not from the `home` page itself.
|
|
166
|
+
|
|
167
|
+
Then open your personal workspace route. The page itself is deliberately light. `src/pages/w/[workspaceSlug]/index.vue` mostly exists to prove that the `app` surface is now real and ready to host later modules.
|
|
168
|
+
|
|
169
|
+
Next open the admin surface for the same workspace. This is the matching pattern on the admin side: `src/pages/w/[workspaceSlug]/admin.vue` is the shell wrapper, `src/pages/w/[workspaceSlug]/admin/index.vue` is the starter page, and the top-right workspace tools button is coming from placements rather than being hand-built into that page file.
|
|
170
|
+
|
|
171
|
+
Finally open the nested workspace settings route. This is useful to inspect because it shows the container pattern most clearly. `src/pages/w/[workspaceSlug]/admin/workspace/settings.vue` owns the section frame and the child outlet, while the actual settings sub-pages can keep arriving later under that shell.
|
|
172
|
+
|
|
173
|
+
## What the workspace packages add to the app
|
|
174
|
+
|
|
175
|
+
This chapter changes the app in four main places:
|
|
176
|
+
|
|
177
|
+
- public config
|
|
178
|
+
- surface access policies
|
|
179
|
+
- migrations
|
|
180
|
+
- workspace surface route files and placements
|
|
181
|
+
|
|
182
|
+
### `config/public.js` changes in a big way
|
|
183
|
+
|
|
184
|
+
The first change is the explicit tenancy mode:
|
|
185
|
+
|
|
186
|
+
```js
|
|
187
|
+
config.tenancyMode = "personal";
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
Then the app gets two new surface definitions:
|
|
191
|
+
|
|
192
|
+
```js
|
|
193
|
+
config.surfaceDefinitions.app = {
|
|
194
|
+
id: "app",
|
|
195
|
+
label: "App",
|
|
196
|
+
pagesRoot: "w/[workspaceSlug]",
|
|
197
|
+
enabled: true,
|
|
198
|
+
requiresAuth: true,
|
|
199
|
+
requiresWorkspace: true,
|
|
200
|
+
accessPolicyId: "workspace_member",
|
|
201
|
+
origin: ""
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
config.surfaceDefinitions.admin = {
|
|
205
|
+
id: "admin",
|
|
206
|
+
label: "Admin",
|
|
207
|
+
pagesRoot: "w/[workspaceSlug]/admin",
|
|
208
|
+
enabled: true,
|
|
209
|
+
requiresAuth: true,
|
|
210
|
+
requiresWorkspace: true,
|
|
211
|
+
accessPolicyId: "workspace_member",
|
|
212
|
+
origin: ""
|
|
213
|
+
};
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
And the app also gains workspace-level feature config:
|
|
217
|
+
|
|
218
|
+
```js
|
|
219
|
+
config.workspaceSwitching = true;
|
|
220
|
+
config.workspaceInvitations = {
|
|
221
|
+
enabled: true,
|
|
222
|
+
allowInPersonalMode: true
|
|
223
|
+
};
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Those lines are the public contract that tells both client and server, "this app is workspace-aware now."
|
|
227
|
+
|
|
228
|
+
### `config/surfaceAccessPolicies.js` gains `workspace_member`
|
|
229
|
+
|
|
230
|
+
The new workspace surfaces use a workspace membership rule:
|
|
231
|
+
|
|
232
|
+
```js
|
|
233
|
+
surfaceAccessPolicies.workspace_member = {
|
|
234
|
+
requireAuth: true,
|
|
235
|
+
requireWorkspaceMembership: true
|
|
236
|
+
};
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
This is the first time the guide shows a surface guarded not just by auth or a simple flag, but by real workspace membership.
|
|
240
|
+
|
|
241
|
+
That is the core idea of multi-homing in JSKIT:
|
|
242
|
+
|
|
243
|
+
- the route contains a workspace slug
|
|
244
|
+
- the server resolves that workspace
|
|
245
|
+
- access depends on whether the current user belongs to it
|
|
246
|
+
|
|
247
|
+
### The migrations now include workspace schema
|
|
248
|
+
|
|
249
|
+
After `workspaces-core`, the migration directory grows again with files such as:
|
|
250
|
+
|
|
251
|
+
```text
|
|
252
|
+
migrations/
|
|
253
|
+
2026..._workspaces-core-initial-schema.cjs
|
|
254
|
+
2026..._users-core-workspace-settings-single-name-source.cjs
|
|
255
|
+
2026..._users-core-workspaces-drop-color.cjs
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
These are the tables and schema changes that make workspace tenancy real in the database.
|
|
259
|
+
|
|
260
|
+
That is why the chapter needs another `npm run db:migrate`. Without those tables, the workspace runtime would have routes and UI, but nowhere to persist workspace membership and settings.
|
|
261
|
+
|
|
262
|
+
### The route tree gains workspace-dependent pages
|
|
263
|
+
|
|
264
|
+
The app now gets:
|
|
265
|
+
|
|
266
|
+
```text
|
|
267
|
+
src/pages/w/[workspaceSlug].vue
|
|
268
|
+
src/pages/w/[workspaceSlug]/index.vue
|
|
269
|
+
src/pages/w/[workspaceSlug]/admin.vue
|
|
270
|
+
src/pages/w/[workspaceSlug]/admin/index.vue
|
|
271
|
+
src/pages/w/[workspaceSlug]/admin/members/index.vue
|
|
272
|
+
src/pages/w/[workspaceSlug]/admin/workspace/settings.vue
|
|
273
|
+
src/pages/w/[workspaceSlug]/admin/workspace/settings/index.vue
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
That list shows the first real nested workspace topology.
|
|
277
|
+
|
|
278
|
+
- `w/[workspaceSlug].vue` is the `app` surface wrapper
|
|
279
|
+
- `w/[workspaceSlug]/index.vue` is the starter landing page for the `app` surface
|
|
280
|
+
- `w/[workspaceSlug]/admin.vue` is the `admin` surface wrapper
|
|
281
|
+
- `w/[workspaceSlug]/admin/index.vue` is the starter landing page for the `admin` surface
|
|
282
|
+
- `w/[workspaceSlug]/admin/members/index.vue` mounts the first real workspace admin client element
|
|
283
|
+
- `w/[workspaceSlug]/admin/workspace/settings.vue` is a local section shell for nested workspace settings routes
|
|
284
|
+
- `w/[workspaceSlug]/admin/workspace/settings/index.vue` is the default child route for that settings shell
|
|
285
|
+
|
|
286
|
+
So the workspace surface model is not only a config concept. It becomes a real file-based routing tree in `src/pages/`.
|
|
287
|
+
|
|
288
|
+
These files are intentionally thinner than they look.
|
|
289
|
+
|
|
290
|
+
Most of the machinery happens up-hill from them:
|
|
291
|
+
|
|
292
|
+
- `config/public.js` defines which surfaces exist and which path roots they own
|
|
293
|
+
- `config/surfaceAccessPolicies.js` defines the membership rule that guards them
|
|
294
|
+
- `src/placement.js` wires the selector, invites cue, and admin tools into the shell
|
|
295
|
+
- `workspaces-core` and `workspaces-web` provide the bootstrap, workspace resolution, permissions, settings, and reusable client elements underneath those routes
|
|
296
|
+
|
|
297
|
+
So the `src/pages` files are mostly containers and composition points, not the place where workspace tenancy is implemented.
|
|
298
|
+
|
|
299
|
+
Concretely, that route tree works like this:
|
|
300
|
+
|
|
301
|
+
- `w/[workspaceSlug].vue` and `w/[workspaceSlug]/admin.vue` are almost pure wrappers. They tag the route with the correct surface id and mount `ShellLayout` plus a child `<RouterView />`.
|
|
302
|
+
- `w/[workspaceSlug]/index.vue` and `w/[workspaceSlug]/admin/index.vue` are intentionally simple starter cards. They prove that the new workspace surfaces are live, but they are meant to be replaced by real product modules later.
|
|
303
|
+
- `w/[workspaceSlug]/admin/members/index.vue` is still thin, but in a different way: it mostly hands control to a packaged `WorkspaceMembersClientElement`, so the route file stays small while the reusable member-management behavior lives in `workspaces-web`.
|
|
304
|
+
- `w/[workspaceSlug]/admin/workspace/settings.vue` is a section shell. It does not own the actual settings fields. It owns the card frame, the left-side settings menu outlet, and the nested `<RouterView />` where child settings pages render.
|
|
305
|
+
- `w/[workspaceSlug]/admin/workspace/settings/index.vue` is intentionally almost empty. Its job is to make `/admin/workspace/settings` a real route today and give you a clean place to redirect or add child settings pages later.
|
|
306
|
+
|
|
307
|
+
### Workspace pages are prepared for missing-workspace states
|
|
308
|
+
|
|
309
|
+
The starter workspace pages already use a dedicated unavailable-state helper:
|
|
310
|
+
|
|
311
|
+
```vue
|
|
312
|
+
<WorkspaceNotFoundCard
|
|
313
|
+
v-if="workspaceUnavailable"
|
|
314
|
+
:message="workspaceUnavailableMessage"
|
|
315
|
+
surface-label="App"
|
|
316
|
+
/>
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
That is worth noticing because it shows that workspace routing is not just string matching on `[workspaceSlug]`. The runtime is expected to decide whether the requested workspace is actually valid and accessible.
|
|
320
|
+
|
|
321
|
+
This is another example of the "mostly containers" pattern. The page file does not resolve the workspace itself. It asks the shared `useWorkspaceNotFoundState()` helper for the current workspace-bootstrap status and then swaps between:
|
|
322
|
+
|
|
323
|
+
- a shared unavailable card when the workspace is missing or inaccessible
|
|
324
|
+
- the local starter content when the workspace context is valid
|
|
325
|
+
|
|
326
|
+
So the starter pages already distinguish:
|
|
327
|
+
|
|
328
|
+
- valid workspace context
|
|
329
|
+
- invalid or inaccessible workspace context
|
|
330
|
+
|
|
331
|
+
### The public workspace client API for custom pages
|
|
332
|
+
|
|
333
|
+
At this point in the chapter, it is worth separating two different kinds of client-side helpers:
|
|
334
|
+
|
|
335
|
+
- app-owned scaffold helpers written into `src/`
|
|
336
|
+
- public package helpers exported by `@jskit-ai/workspaces-web`
|
|
337
|
+
|
|
338
|
+
`useWorkspaceNotFoundState()` belongs to the first group. It is an app-owned helper scaffolded into:
|
|
339
|
+
|
|
340
|
+
```text
|
|
341
|
+
src/composables/useWorkspaceNotFoundState.js
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
That makes it easy to customize locally.
|
|
345
|
+
|
|
346
|
+
The main app-author-facing helper exported by `workspaces-web` itself is:
|
|
347
|
+
|
|
348
|
+
```js
|
|
349
|
+
import { useWorkspaceRouteContext } from "@jskit-ai/workspaces-web/client/composables/useWorkspaceRouteContext";
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
That is the public composable most custom workspace pages should reach for first.
|
|
353
|
+
|
|
354
|
+
#### What `workspaces-web` actually exposes publicly on the client side
|
|
355
|
+
|
|
356
|
+
Today, the public client surface is intentionally small.
|
|
357
|
+
|
|
358
|
+
- `@jskit-ai/workspaces-web/client`
|
|
359
|
+
- the package's client runtime registration surface
|
|
360
|
+
- exports `clientProviders`, `WorkspacesWebClientProvider`, and `WorkspaceMembersClientElement`
|
|
361
|
+
- `@jskit-ai/workspaces-web/client/composables/useWorkspaceRouteContext`
|
|
362
|
+
- the main public page-level composable for workspace-aware route context
|
|
363
|
+
|
|
364
|
+
That is a useful distinction.
|
|
365
|
+
|
|
366
|
+
- `WorkspacesWebClientProvider` and `clientProviders` are runtime wiring, not something a normal page imports.
|
|
367
|
+
- `WorkspaceMembersClientElement` is a packaged feature element that a route can render directly.
|
|
368
|
+
- `useWorkspaceRouteContext()` is the public helper most app-authored workspace pages will actually use.
|
|
369
|
+
|
|
370
|
+
There are other helpers inside the package source, but if they are not exported by the package, treat them as internal implementation details rather than app code API.
|
|
371
|
+
|
|
372
|
+
#### What `useWorkspaceRouteContext()` gives you
|
|
373
|
+
|
|
374
|
+
The composable returns:
|
|
375
|
+
|
|
376
|
+
- `route`
|
|
377
|
+
- the live Vue Router route object
|
|
378
|
+
- `routePath`
|
|
379
|
+
- the normalized runtime pathname
|
|
380
|
+
- `currentSurfaceId`
|
|
381
|
+
- the resolved current surface id, such as `app` or `admin`
|
|
382
|
+
- `workspaceSlugFromRoute`
|
|
383
|
+
- the current workspace slug, but only when the current route really belongs to a workspace-dependent surface
|
|
384
|
+
- `placementContext`
|
|
385
|
+
- the current shell placement/bootstrap context
|
|
386
|
+
- `mergePlacementContext`
|
|
387
|
+
- the function used to merge new context back into the shell runtime
|
|
388
|
+
|
|
389
|
+
For most custom pages, the two values you care about most are:
|
|
390
|
+
|
|
391
|
+
- `workspaceSlugFromRoute`
|
|
392
|
+
- `currentSurfaceId`
|
|
393
|
+
|
|
394
|
+
#### Why use it instead of reading `$route.params.workspaceSlug` directly
|
|
395
|
+
|
|
396
|
+
For a very simple page, reading the raw route param can work.
|
|
397
|
+
|
|
398
|
+
But `useWorkspaceRouteContext()` is the better default for workspace-aware app code because it does more than "read a param":
|
|
399
|
+
|
|
400
|
+
- it resolves the current surface through the shell placement/runtime context
|
|
401
|
+
- it normalizes the current route path before extracting anything
|
|
402
|
+
- it only returns a workspace slug when the current surface is actually workspace-scoped
|
|
403
|
+
- it works the same way on both workspace surfaces, `app` and `admin`
|
|
404
|
+
|
|
405
|
+
That means your page logic stays aligned with the same route model that the packaged workspace components use internally.
|
|
406
|
+
|
|
407
|
+
In other words:
|
|
408
|
+
|
|
409
|
+
- `$route.params.workspaceSlug` is a raw route detail
|
|
410
|
+
- `useWorkspaceRouteContext()` is a workspace-aware view of the current route
|
|
411
|
+
|
|
412
|
+
#### A concrete custom page example
|
|
413
|
+
|
|
414
|
+
Suppose you create a real admin page at:
|
|
415
|
+
|
|
416
|
+
```text
|
|
417
|
+
src/pages/w/[workspaceSlug]/admin/reports/index.vue
|
|
418
|
+
```
|
|
419
|
+
|
|
420
|
+
and that page needs to:
|
|
421
|
+
|
|
422
|
+
- know which workspace it is looking at
|
|
423
|
+
- know that it is running on the `admin` surface
|
|
424
|
+
- build a workspace-scoped API request or query key
|
|
425
|
+
|
|
426
|
+
That is exactly the kind of page `useWorkspaceRouteContext()` is for:
|
|
427
|
+
|
|
428
|
+
```vue
|
|
429
|
+
<script setup>
|
|
430
|
+
import { computed } from "vue";
|
|
431
|
+
import { usePaths } from "@jskit-ai/users-web/client/composables/usePaths";
|
|
432
|
+
import { useWorkspaceRouteContext } from "@jskit-ai/workspaces-web/client/composables/useWorkspaceRouteContext";
|
|
433
|
+
|
|
434
|
+
const { workspaceSlugFromRoute, currentSurfaceId } = useWorkspaceRouteContext();
|
|
435
|
+
const paths = usePaths();
|
|
436
|
+
|
|
437
|
+
const reportsApiPath = computed(() => {
|
|
438
|
+
if (!workspaceSlugFromRoute.value) {
|
|
439
|
+
return "";
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
return paths.api("/reports", {
|
|
443
|
+
params: {
|
|
444
|
+
workspaceSlug: workspaceSlugFromRoute.value
|
|
445
|
+
}
|
|
446
|
+
});
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
const queryKey = computed(() => ([
|
|
450
|
+
"workspace-reports",
|
|
451
|
+
currentSurfaceId.value,
|
|
452
|
+
workspaceSlugFromRoute.value
|
|
453
|
+
]));
|
|
454
|
+
</script>
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
That pattern is intentionally boring in the right way.
|
|
458
|
+
|
|
459
|
+
- the page does not hard-code path parsing rules itself
|
|
460
|
+
- the page gets a normalized workspace slug from the public workspace helper
|
|
461
|
+
- the query key can still distinguish between `app` and `admin` when needed
|
|
462
|
+
|
|
463
|
+
The same composable works just as well in a custom workspace app page under:
|
|
464
|
+
|
|
465
|
+
```text
|
|
466
|
+
src/pages/w/[workspaceSlug]/index.vue
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
or any later child page below that surface.
|
|
470
|
+
|
|
471
|
+
#### When you need the rest of the returned context
|
|
472
|
+
|
|
473
|
+
Most custom pages only need:
|
|
474
|
+
|
|
475
|
+
- `workspaceSlugFromRoute`
|
|
476
|
+
- `currentSurfaceId`
|
|
477
|
+
- maybe `route`
|
|
478
|
+
|
|
479
|
+
The other returned values are there for more advanced cases.
|
|
480
|
+
|
|
481
|
+
- `placementContext` matters when a page needs to read the current shell/bootstrap context directly, for example available workspaces or current permissions already in the shell state.
|
|
482
|
+
- `mergePlacementContext` is for pages that need to push refreshed workspace data back into the shell runtime after a fetch or save.
|
|
483
|
+
|
|
484
|
+
That second case is real, but it is more advanced. It is what packaged elements such as the workspace settings client use when they need the shell's current workspace badge, selector state, or permissions to refresh after a change.
|
|
485
|
+
|
|
486
|
+
For normal custom page code, you usually do **not** start there. Start with `workspaceSlugFromRoute`.
|
|
487
|
+
|
|
488
|
+
### `src/placement.js` becomes workspace-aware
|
|
489
|
+
|
|
490
|
+
The workspace packages append a new block of placements:
|
|
491
|
+
|
|
492
|
+
```js
|
|
493
|
+
addPlacement({
|
|
494
|
+
id: "workspaces.profile.menu.surface-switch",
|
|
495
|
+
target: "auth-profile-menu:primary-menu",
|
|
496
|
+
surfaces: ["*"],
|
|
497
|
+
order: 100,
|
|
498
|
+
componentToken: "workspaces.web.profile.menu.surface-switch-item",
|
|
499
|
+
when: ({ auth }) => Boolean(auth?.authenticated)
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
addPlacement({
|
|
503
|
+
id: "workspaces.workspace.selector",
|
|
504
|
+
target: "shell-layout:top-left",
|
|
505
|
+
surfaces: ["*"],
|
|
506
|
+
order: 200,
|
|
507
|
+
componentToken: "workspaces.web.workspace.selector",
|
|
508
|
+
props: {
|
|
509
|
+
allowOnNonWorkspaceSurface: true,
|
|
510
|
+
targetSurfaceId: "app"
|
|
511
|
+
},
|
|
512
|
+
when: ({ auth }) => {
|
|
513
|
+
return Boolean(auth?.authenticated);
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
addPlacement({
|
|
518
|
+
id: "workspaces.account.invites.cue",
|
|
519
|
+
target: "shell-layout:top-right",
|
|
520
|
+
surfaces: ["*"],
|
|
521
|
+
order: 850,
|
|
522
|
+
componentToken: "local.main.account.pending-invites.cue",
|
|
523
|
+
when: ({ auth }) => Boolean(auth?.authenticated)
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
addPlacement({
|
|
527
|
+
id: "workspaces.workspace.tools.widget",
|
|
528
|
+
target: "shell-layout:top-right",
|
|
529
|
+
surfaces: ["admin"],
|
|
530
|
+
order: 900,
|
|
531
|
+
componentToken: "workspaces.web.workspace.tools.widget"
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
addPlacement({
|
|
535
|
+
id: "workspaces.workspace.menu.workspace-settings",
|
|
536
|
+
target: "workspace-tools:primary-menu",
|
|
537
|
+
surfaces: ["admin"],
|
|
538
|
+
order: 100,
|
|
539
|
+
componentToken: "workspaces.web.workspace-settings.menu-item"
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
addPlacement({
|
|
543
|
+
id: "workspaces.workspace.menu.members",
|
|
544
|
+
target: "workspace-tools:primary-menu",
|
|
545
|
+
surfaces: ["admin"],
|
|
546
|
+
order: 200,
|
|
547
|
+
componentToken: "workspaces.web.workspace-members.menu-item"
|
|
548
|
+
});
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
That one block explains a lot of the new shell behavior.
|
|
552
|
+
|
|
553
|
+
- the authenticated profile menu can now switch into workspace surfaces
|
|
554
|
+
- the top-left area now has a workspace selector
|
|
555
|
+
- the top-right area can show a pending-invites cue
|
|
556
|
+
- the admin surface gets workspace tools in the top-right area
|
|
557
|
+
- the admin workspace settings menu is now another nested placement host with both `Settings` and `Members`
|
|
558
|
+
|
|
559
|
+
So the placement system from the shell chapter is still doing the same job as before. The app just has a richer routing and tenancy context now.
|
|
560
|
+
|
|
561
|
+
### The local client provider gets one more app-owned token
|
|
562
|
+
|
|
563
|
+
`workspaces-web` also appends an app-owned component registration:
|
|
564
|
+
|
|
565
|
+
```js
|
|
566
|
+
registerMainClientComponent("local.main.account.pending-invites.cue", () => AccountPendingInvitesCue);
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
That is the pending-invites cue used in the shell when workspace invitations exist.
|
|
570
|
+
|
|
571
|
+
This is worth noticing because it follows the same app-owned token pattern the guide has shown before:
|
|
572
|
+
|
|
573
|
+
- the package installs an app-owned component file
|
|
574
|
+
- the app-local provider publishes it under a stable token
|
|
575
|
+
- placements can then render it through the shell
|
|
576
|
+
|
|
577
|
+
## Under the hood
|
|
578
|
+
|
|
579
|
+
### `workspaces-core` plugs into the users profile-sync registry
|
|
580
|
+
|
|
581
|
+
There is also an important server-side integration point that is easy to miss if you only look at routes and pages.
|
|
582
|
+
|
|
583
|
+
In the previous chapter, `users-core` introduced the tagged profile-sync lifecycle registry that runs after a JSKIT user record has been synchronized from auth. `workspaces-core` uses that seam by registering a contributor:
|
|
584
|
+
|
|
585
|
+
```js
|
|
586
|
+
registerProfileSyncLifecycleContributor(app, "workspaces.core.profileSyncLifecycleContributor", (scope) => {
|
|
587
|
+
const workspaceService = scope.make("workspaces.service");
|
|
588
|
+
|
|
589
|
+
return Object.freeze({
|
|
590
|
+
contributorId: "workspaces.core.profileSync",
|
|
591
|
+
order: 100,
|
|
592
|
+
async afterIdentityProfileSynced({ profile, created, options } = {}) {
|
|
593
|
+
if (!created || !profile || typeof workspaceService?.provisionWorkspaceForNewUser !== "function") {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
await workspaceService.provisionWorkspaceForNewUser(profile, options);
|
|
598
|
+
}
|
|
599
|
+
});
|
|
600
|
+
});
|
|
601
|
+
```
|
|
602
|
+
|
|
603
|
+
That means the workspace package does not need to patch auth directly to learn that a user was added. It listens through the `users-core` lifecycle registry instead.
|
|
604
|
+
|
|
605
|
+
For this chapter's `tenancyMode = "personal"` setup, that contributor now does real work. When a brand-new JSKIT user is synchronized from auth, `workspaces-core` uses the lifecycle seam to provision that user's first personal workspace automatically.
|
|
606
|
+
|
|
607
|
+
- `users-core` owns the "user was synchronized" lifecycle
|
|
608
|
+
- `workspaces-core` subscribes to that lifecycle through the registry
|
|
609
|
+
- tenancy policy decides whether the workspace layer provisions a personal workspace automatically
|
|
610
|
+
|
|
611
|
+
So even in this chapter, the package boundary is already correct: users owns user creation/sync, and workspaces reacts through an extension point.
|
|
612
|
+
|
|
613
|
+
### Why this chapter is the real routing pivot
|
|
614
|
+
|
|
615
|
+
Earlier chapters added features inside a flat top-level app.
|
|
616
|
+
|
|
617
|
+
This chapter is different. It changes the shape of the app itself.
|
|
618
|
+
|
|
619
|
+
Before:
|
|
620
|
+
|
|
621
|
+
- global surfaces only
|
|
622
|
+
- no workspace slug in routes
|
|
623
|
+
- no workspace membership checks
|
|
624
|
+
|
|
625
|
+
After:
|
|
626
|
+
|
|
627
|
+
- global surfaces still exist
|
|
628
|
+
- workspace-scoped surfaces now exist too
|
|
629
|
+
- the shell can navigate between workspaces
|
|
630
|
+
- access to some surfaces now depends on workspace membership
|
|
631
|
+
|
|
632
|
+
That is why multi-homing deserves its own chapter. It is not just another feature package. It is the moment the app becomes tenancy-aware.
|
|
633
|
+
|
|
634
|
+
## Summary
|
|
635
|
+
|
|
636
|
+
This chapter is the real routing and tenancy pivot in the guide.
|
|
637
|
+
|
|
638
|
+
- the app now uses `tenancyMode = "personal"`
|
|
639
|
+
- `workspaces-core` added the persistent schema and server runtime for workspaces
|
|
640
|
+
- `workspaces-web` added the first workspace-scoped surfaces, shell controls, and the workspace-owned account invites extension
|
|
641
|
+
|
|
642
|
+
At the end of this chapter, the app now has both:
|
|
643
|
+
|
|
644
|
+
- global surfaces such as `home`, `auth`, `account`, and `console`
|
|
645
|
+
- workspace-scoped surfaces such as `/w/[workspaceSlug]` and `/w/[workspaceSlug]/admin`
|
|
646
|
+
|
|
647
|
+
That is the most important mental shift to keep:
|
|
648
|
+
|
|
649
|
+
- earlier chapters added features inside one global app shell
|
|
650
|
+
- this chapter changed the topology of the app itself
|
|
651
|
+
|
|
652
|
+
From here on, later modules are no longer only adding pages or widgets. They can add features inside either:
|
|
653
|
+
|
|
654
|
+
- the global surfaces
|
|
655
|
+
- the workspace-specific surfaces
|