@jskit-ai/workspaces-web 0.1.228 → 0.1.229

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.
@@ -0,0 +1,2 @@
1
+ <!doctype html>
2
+ <html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>Your workspaces</title></head><body><div id="app"></div><script type="module" src="/main.js"></script></body></html>
@@ -0,0 +1,46 @@
1
+ import { createApp, h } from "vue";
2
+ import { createRouter, createWebHistory, RouterView, useRoute } from "vue-router";
3
+ import { QueryClient, VueQueryPlugin } from "@tanstack/vue-query";
4
+ import "vuetify/styles";
5
+ import { createVuetify } from "vuetify";
6
+ import * as components from "vuetify/components";
7
+ import * as directives from "vuetify/directives";
8
+ import { aliases, mdi } from "vuetify/iconsets/mdi-svg";
9
+ import WorkspacesClientElement from "../../src/client/components/WorkspacesClientElement.vue";
10
+
11
+ const context = {
12
+ surfaceConfig: {
13
+ tenancyMode: "workspaces",
14
+ defaultSurfaceId: "home",
15
+ enabledSurfaceIds: ["home", "app"],
16
+ surfacesById: {
17
+ home: { id: "home", enabled: true, pagesRoot: "home", routeBase: "/home", requiresWorkspace: false },
18
+ app: { id: "app", enabled: true, pagesRoot: "w/[workspaceSlug]", routeBase: "/w/:workspaceSlug", requiresWorkspace: true }
19
+ }
20
+ }
21
+ };
22
+ const OpenedWorkspace = {
23
+ setup() {
24
+ const route = useRoute();
25
+ return () => h("p", `Opened ${route.params.workspaceSlug}`);
26
+ }
27
+ };
28
+ const router = createRouter({
29
+ history: createWebHistory(),
30
+ routes: [
31
+ { path: "/home/workspaces", component: WorkspacesClientElement },
32
+ { path: "/w/:workspaceSlug", component: OpenedWorkspace }
33
+ ]
34
+ });
35
+ const app = createApp({ render: () => h(components.VApp, null, { default: () => h(components.VMain, null, { default: () => h(RouterView) }) }) });
36
+ app.provide("jskit.shell-web.runtime.web-placement.client", {
37
+ getContext: () => context,
38
+ getPlacements: () => [],
39
+ subscribe: () => () => {},
40
+ setContext: () => context
41
+ });
42
+ app.use(router);
43
+ app.use(VueQueryPlugin, { queryClient: new QueryClient({ defaultOptions: { queries: { retry: false } } }) });
44
+ app.use(createVuetify({ components, directives, icons: { defaultSet: "mdi", aliases, sets: { mdi } } }));
45
+ await router.isReady();
46
+ app.mount("#app");
@@ -0,0 +1,9 @@
1
+ import { fileURLToPath } from "node:url";
2
+ import { defineConfig } from "vite";
3
+ import vue from "@vitejs/plugin-vue";
4
+
5
+ export default defineConfig({
6
+ root: fileURLToPath(new URL("./", import.meta.url)),
7
+ plugins: [vue()],
8
+ server: { host: "127.0.0.1", strictPort: true }
9
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/workspaces-web",
3
- "version": "0.1.228",
3
+ "version": "0.1.229",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "node --test --test-concurrency=1"
@@ -9,21 +9,22 @@
9
9
  "./client": "./src/client/index.js",
10
10
  "./client/components/AccountSettingsInvitesSection": "./src/client/components/AccountSettingsInvitesSection.vue",
11
11
  "./client/components/WorkspaceInviteLanding": "./src/client/components/WorkspaceInviteLanding.vue",
12
+ "./client/components/WorkspacesClientElement": "./src/client/components/WorkspacesClientElement.vue",
12
13
  "./client/providers/WorkspacesWebClientProvider": "./src/client/providers/WorkspacesWebClientProvider.js",
13
14
  "./client/components/WorkspaceMembersClientElement": "./src/client/components/WorkspaceMembersClientElement.vue",
14
15
  "./client/composables/useWorkspaceRouteContext": "./src/client/composables/useWorkspaceRouteContext.js"
15
16
  },
16
17
  "dependencies": {
17
- "@jskit-ai/users-core": "0.1.259",
18
- "@jskit-ai/workspaces-core": "0.1.224",
18
+ "@jskit-ai/users-core": "0.1.260",
19
+ "@jskit-ai/workspaces-core": "0.1.225",
19
20
  "@mdi/js": "^7.4.47"
20
21
  },
21
22
  "peerDependencies": {
22
- "@jskit-ai/auth-web": "0.1.249",
23
- "@jskit-ai/http-web": "0.1.94",
24
- "@jskit-ai/kernel": "0.1.246",
25
- "@jskit-ai/shell-web": "0.1.253",
26
- "@jskit-ai/users-web": "0.1.267",
23
+ "@jskit-ai/auth-web": "0.1.250",
24
+ "@jskit-ai/http-web": "0.1.95",
25
+ "@jskit-ai/kernel": "0.1.247",
26
+ "@jskit-ai/shell-web": "0.1.254",
27
+ "@jskit-ai/users-web": "0.1.268",
27
28
  "@tanstack/vue-query": "^5.90.5",
28
29
  "vue": "^3.5.13",
29
30
  "vue-router": "^5.0.4",
@@ -70,6 +71,10 @@
70
71
  "subpath": "./client/components/WorkspaceInviteLanding",
71
72
  "summary": "Exports the default public workspace invite landing component."
72
73
  },
74
+ {
75
+ "subpath": "./client/components/WorkspacesClientElement",
76
+ "summary": "Exports the Your workspaces landing page component: last-used or only workspace, otherwise the list, invitations and first-workspace creation."
77
+ },
73
78
  {
74
79
  "subpath": "./client/providers/WorkspacesWebClientProvider",
75
80
  "summary": "Exports workspaces-web client provider class."
@@ -24,6 +24,13 @@ Choose public invitation routes, application/admin surface ids, workspace
24
24
  selector behavior, member-management permissions, settings sections, and the
25
25
  empty or not-found experience.
26
26
 
27
+ Choose where signed-in people land. The default surface does not require a
28
+ workspace, so `/`, invitation links and the **Your workspaces** page work
29
+ without one. Keep a landing page there, or mount `WorkspacesClientElement` on
30
+ it to open the last workspace used in this browser, or the only one, and
31
+ otherwise show the person's workspaces, pending invitations and first-workspace
32
+ creation.
33
+
27
34
  ## Framework APIs
28
35
 
29
36
  Use the workspace client provider, components, and composables exported by
@@ -43,8 +50,9 @@ Use the workspace client provider, components, and composables exported by
43
50
  ## Example files
44
51
 
45
52
  `example/` contains workspace app/admin roots, starter pages, invitation route,
46
- member and settings routes, not-found state, app-owned invitation widgets, and
47
- the components that an application's client provider registers.
53
+ the **Your workspaces** page at `src/pages/home/workspaces/index.vue`, member
54
+ and settings routes, not-found state, app-owned invitation widgets, and the
55
+ components that an application's client provider registers.
48
56
 
49
57
  ## Variation points
50
58
 
@@ -0,0 +1,7 @@
1
+ <template>
2
+ <WorkspacesClientElement />
3
+ </template>
4
+
5
+ <script setup>
6
+ import WorkspacesClientElement from "@jskit-ai/workspaces-web/client/components/WorkspacesClientElement";
7
+ </script>
@@ -186,17 +186,6 @@ const activeWorkspaceLabel = computed(() => {
186
186
  return "Workspace";
187
187
  });
188
188
 
189
- function workspaceAvatarStyle(workspace) {
190
- const color = String(workspace?.color || "").trim();
191
- if (!/^#[0-9a-fA-F]{6}$/.test(color)) {
192
- return {};
193
- }
194
-
195
- return {
196
- backgroundColor: color
197
- };
198
- }
199
-
200
189
  </script>
201
190
 
202
191
  <template>
@@ -224,7 +213,7 @@ function workspaceAvatarStyle(workspace) {
224
213
  @click="navigateToWorkspace(workspace.slug)"
225
214
  >
226
215
  <template #prepend>
227
- <v-avatar size="24" color="primary" variant="tonal" :style="workspaceAvatarStyle(workspace)">
216
+ <v-avatar size="24" color="primary" variant="tonal">
228
217
  <span class="text-caption">{{ String(workspace.name || "W").slice(0, 1).toUpperCase() }}</span>
229
218
  </v-avatar>
230
219
  </template>
@@ -7,6 +7,7 @@ import {
7
7
  } from "@jskit-ai/shell-web/client/placement";
8
8
  import { useShellWebErrorRuntime } from "@jskit-ai/shell-web/client/error";
9
9
  import { normalizeWorkspaceList } from "../lib/bootstrap.js";
10
+ import { readLastWorkspaceSlug, resolveWorkspaceLandingSlug } from "../lib/lastWorkspace.js";
10
11
  import { ROUTE_VISIBILITY_PUBLIC } from "@jskit-ai/kernel/shared/support/visibility";
11
12
  import {
12
13
  WORKSPACES_TRANSPORT,
@@ -59,6 +60,7 @@ const errorRuntime = useShellWebErrorRuntime();
59
60
  const selectingWorkspaceSlug = ref("");
60
61
  const bootstrapModel = reactive({
61
62
  sessionAuthenticated: false,
63
+ userId: "",
62
64
  tenancyMode: "none",
63
65
  workspaceAllowSelfCreate: false,
64
66
  workspaceInvitesEnabled: false,
@@ -91,6 +93,7 @@ const bootstrapView = useView({
91
93
  model: bootstrapModel,
92
94
  mapLoadedToModel: (model, payload = {}) => {
93
95
  model.sessionAuthenticated = Boolean(payload?.session?.authenticated);
96
+ model.userId = String(payload?.session?.userId || "");
94
97
  model.tenancyMode = String(payload?.tenancy?.mode || "").trim().toLowerCase() || "none";
95
98
  model.workspaceAllowSelfCreate = payload?.tenancy?.workspace?.allowSelfCreate === true;
96
99
  model.workspaceInvitesEnabled = payload?.app?.features?.workspaceInvites === true;
@@ -200,17 +203,6 @@ function workspaceInitials(workspace) {
200
203
  return source.slice(0, 2).toUpperCase();
201
204
  }
202
205
 
203
- function workspaceAvatarStyle(workspace) {
204
- const color = String(workspace?.color || "").trim();
205
- if (!/^#[0-9a-fA-F]{6}$/.test(color)) {
206
- return {};
207
- }
208
-
209
- return {
210
- backgroundColor: color
211
- };
212
- }
213
-
214
206
  function workspaceHomePath(workspaceSlug) {
215
207
  const normalizedSlug = String(workspaceSlug || "").trim();
216
208
  if (!normalizedSlug || !workspaceSurfaceId.value) {
@@ -225,6 +217,25 @@ function workspaceHomePath(workspaceSlug) {
225
217
  });
226
218
  }
227
219
 
220
+ function resolveLandingSlug() {
221
+ return resolveWorkspaceLandingSlug({
222
+ workspaces: workspaceItems.value,
223
+ pendingInvites: pendingInvites.value,
224
+ lastWorkspaceSlug: readLastWorkspaceSlug(bootstrapModel.userId)
225
+ });
226
+ }
227
+
228
+ function workspaceOpenLabel(workspace) {
229
+ if (!workspace.isAccessible) {
230
+ return "Unavailable";
231
+ }
232
+ return selectingWorkspaceSlug.value === workspace.slug ? "Opening…" : "Open";
233
+ }
234
+
235
+ function isRespondingToInvite(invite, decision) {
236
+ return inviteAction.value.token === invite.token && inviteAction.value.decision === decision;
237
+ }
238
+
228
239
  async function openWorkspace(workspaceSlug) {
229
240
  const normalizedSlug = String(workspaceSlug || "").trim();
230
241
  if (!normalizedSlug) {
@@ -349,7 +360,7 @@ async function createWorkspace() {
349
360
  const createdWorkspace = await createWorkspaceCommand.run();
350
361
  await bootstrapView.refresh();
351
362
  const createdSlug = String(createdWorkspace?.slug || "").trim();
352
- const autoOpenHandledByWatcher = workspaceItems.value.length === 1 && pendingInvites.value.length < 1;
363
+ const autoOpenHandledByWatcher = Boolean(resolveLandingSlug());
353
364
  if (createdSlug && !autoOpenHandledByWatcher) {
354
365
  await openWorkspace(createdSlug);
355
366
  }
@@ -388,8 +399,9 @@ watch(
388
399
  return;
389
400
  }
390
401
 
391
- if (workspaceItems.value.length === 1 && pendingInvites.value.length < 1) {
392
- await openWorkspace(workspaceItems.value[0].slug);
402
+ const landingSlug = resolveLandingSlug();
403
+ if (landingSlug) {
404
+ await openWorkspace(landingSlug);
393
405
  }
394
406
  },
395
407
  {
@@ -404,12 +416,11 @@ watch(
404
416
  <v-container class="mx-auto" max-width="860">
405
417
  <v-sheet rounded="lg" border class="workspaces-view__panel">
406
418
  <header class="workspaces-view__header">
407
- <h1 class="workspaces-view__title">You are logged in</h1>
419
+ <h1 class="workspaces-view__title">Your workspaces</h1>
408
420
  <p class="text-body-2 text-medium-emphasis mb-0">Select a workspace or respond to invitations.</p>
409
421
  </header>
410
422
 
411
423
  <div class="workspaces-view__body">
412
- <v-progress-linear v-if="!isBootstrapping && isRefreshingBootstrap" indeterminate class="mb-4" />
413
424
  <v-row>
414
425
  <v-col cols="12" :md="workspaceInvitesEnabled ? 6 : 12">
415
426
  <template v-if="isBootstrapping">
@@ -421,14 +432,14 @@ watch(
421
432
  <v-btn
422
433
  color="primary"
423
434
  variant="tonal"
424
- :loading="isRefreshingBootstrap"
435
+ :disabled="isRefreshingBootstrap"
425
436
  @click="refreshBootstrap"
426
437
  >
427
- Retry
438
+ {{ isRefreshingBootstrap ? "Retrying…" : "Retry" }}
428
439
  </v-btn>
429
440
  </div>
430
441
  <template v-else>
431
- <div class="text-subtitle-2 mb-2">Your workspaces</div>
442
+ <div class="text-subtitle-2 mb-2">Workspaces</div>
432
443
  <template v-if="workspaceItems.length === 0">
433
444
  <p class="text-body-1 mb-2">You do not have a workspace yet.</p>
434
445
  <template v-if="canCreateWorkspace">
@@ -451,10 +462,10 @@ watch(
451
462
  <v-btn
452
463
  color="primary"
453
464
  variant="tonal"
454
- :loading="isCreatingWorkspace"
465
+ :disabled="isCreatingWorkspace"
455
466
  @click="createWorkspace"
456
467
  >
457
- Create Workspace
468
+ {{ isCreatingWorkspace ? "Creating…" : "Create Workspace" }}
458
469
  </v-btn>
459
470
  </template>
460
471
  <p v-else class="text-body-2 text-medium-emphasis mb-0">
@@ -476,7 +487,7 @@ watch(
476
487
  class="px-0"
477
488
  >
478
489
  <template #prepend>
479
- <v-avatar :style="workspaceAvatarStyle(workspace)" size="28">
490
+ <v-avatar color="primary" variant="tonal" size="28">
480
491
  <v-img v-if="workspace.avatarUrl" :src="workspace.avatarUrl" cover />
481
492
  <span v-else class="text-caption">{{ workspaceInitials(workspace) }}</span>
482
493
  </v-avatar>
@@ -486,11 +497,10 @@ watch(
486
497
  color="primary"
487
498
  size="small"
488
499
  variant="tonal"
489
- :disabled="!workspace.isAccessible"
490
- :loading="selectingWorkspaceSlug === workspace.slug"
500
+ :disabled="!workspace.isAccessible || selectingWorkspaceSlug === workspace.slug"
491
501
  @click="openWorkspace(workspace.slug)"
492
502
  >
493
- {{ workspace.isAccessible ? "Open" : "Unavailable" }}
503
+ {{ workspaceOpenLabel(workspace) }}
494
504
  </v-btn>
495
505
  </template>
496
506
  </v-list-item>
@@ -529,19 +539,19 @@ watch(
529
539
  size="small"
530
540
  variant="text"
531
541
  color="error"
532
- :loading="inviteAction.token === invite.token && inviteAction.decision === 'refuse'"
542
+ :disabled="isRespondingToInvite(invite, 'refuse')"
533
543
  @click="refuseInvite(invite)"
534
544
  >
535
- Refuse
545
+ {{ isRespondingToInvite(invite, "refuse") ? "Refusing…" : "Refuse" }}
536
546
  </v-btn>
537
547
  <v-btn
538
548
  size="small"
539
549
  variant="tonal"
540
550
  color="primary"
541
- :loading="inviteAction.token === invite.token && inviteAction.decision === 'accept'"
551
+ :disabled="isRespondingToInvite(invite, 'accept')"
542
552
  @click="acceptInvite(invite)"
543
553
  >
544
- Join
554
+ {{ isRespondingToInvite(invite, "accept") ? "Joining…" : "Join" }}
545
555
  </v-btn>
546
556
  </div>
547
557
  </template>
@@ -585,13 +595,13 @@ watch(
585
595
  text-align: center;
586
596
  }
587
597
 
598
+ .workspaces-view__body :deep(.v-btn) {
599
+ min-height: 48px;
600
+ }
601
+
588
602
  @media (max-width: 640px) {
589
603
  .workspaces-view {
590
604
  padding-block: 0.75rem !important;
591
605
  }
592
-
593
- .workspaces-view__body :deep(.v-btn) {
594
- min-height: 48px;
595
- }
596
606
  }
597
607
  </style>
@@ -1,3 +1,4 @@
1
1
  export { WorkspacesWebClientProvider } from "./providers/WorkspacesWebClientProvider.js";
2
2
  export { default as WorkspaceMembersClientElement } from "./components/WorkspaceMembersClientElement.vue";
3
3
  export { default as WorkspaceInviteLanding } from "./components/WorkspaceInviteLanding.vue";
4
+ export { default as WorkspacesClientElement } from "./components/WorkspacesClientElement.vue";
@@ -0,0 +1,66 @@
1
+ import { normalizeRecordId } from "@jskit-ai/kernel/shared/support/normalize";
2
+ import { findWorkspaceBySlug } from "./bootstrap.js";
3
+
4
+ const LAST_WORKSPACE_STORAGE_KEY_PREFIX = "jskit.workspaces-web.last-workspace.";
5
+
6
+ function resolveStorage(storage) {
7
+ if (storage !== undefined) {
8
+ return storage;
9
+ }
10
+ try {
11
+ return typeof window === "object" ? window?.localStorage || null : null;
12
+ } catch {
13
+ return null;
14
+ }
15
+ }
16
+
17
+ function lastWorkspaceStorageKey(userId) {
18
+ const normalizedUserId = normalizeRecordId(userId, { fallback: "" });
19
+ return normalizedUserId ? `${LAST_WORKSPACE_STORAGE_KEY_PREFIX}${normalizedUserId}` : "";
20
+ }
21
+
22
+ function readLastWorkspaceSlug(userId, { storage } = {}) {
23
+ const key = lastWorkspaceStorageKey(userId);
24
+ const resolvedStorage = resolveStorage(storage);
25
+ if (!key || !resolvedStorage || typeof resolvedStorage.getItem !== "function") {
26
+ return "";
27
+ }
28
+
29
+ try {
30
+ return String(resolvedStorage.getItem(key) || "").trim();
31
+ } catch {
32
+ return "";
33
+ }
34
+ }
35
+
36
+ function writeLastWorkspaceSlug(userId, workspaceSlug, { storage } = {}) {
37
+ const key = lastWorkspaceStorageKey(userId);
38
+ const normalizedWorkspaceSlug = String(workspaceSlug || "").trim();
39
+ const resolvedStorage = resolveStorage(storage);
40
+ if (!key || !normalizedWorkspaceSlug || !resolvedStorage || typeof resolvedStorage.setItem !== "function") {
41
+ return;
42
+ }
43
+
44
+ try {
45
+ resolvedStorage.setItem(key, normalizedWorkspaceSlug);
46
+ } catch {
47
+ // Ignore localStorage write failures in unsupported or locked-down environments.
48
+ }
49
+ }
50
+
51
+ // Pending invitations keep the person on the workspaces page; otherwise open the
52
+ // last workspace used in this browser, or the only one they have.
53
+ function resolveWorkspaceLandingSlug({ workspaces = [], pendingInvites = [], lastWorkspaceSlug = "" } = {}) {
54
+ if (pendingInvites.length > 0) {
55
+ return "";
56
+ }
57
+
58
+ const lastWorkspace = findWorkspaceBySlug(workspaces, lastWorkspaceSlug);
59
+ if (lastWorkspace?.isAccessible) {
60
+ return lastWorkspace.slug;
61
+ }
62
+
63
+ return workspaces.length === 1 ? workspaces[0].slug : "";
64
+ }
65
+
66
+ export { readLastWorkspaceSlug, resolveWorkspaceLandingSlug, writeLastWorkspaceSlug };
@@ -154,7 +154,7 @@ function setVuetifyThemeName(themeController, themeName) {
154
154
  if (themeController.global.name.value === normalizedThemeName) {
155
155
  return false;
156
156
  }
157
- themeController.global.name.value = normalizedThemeName;
157
+ themeController.change(normalizedThemeName);
158
158
  return true;
159
159
  }
160
160
 
@@ -283,7 +283,7 @@ function setVuetifyPrimaryColorOverride(themeController, themeInput = null) {
283
283
  if (currentThemeName === normalizedThemeName) {
284
284
  return false;
285
285
  }
286
- themeController.global.name.value = normalizedThemeName;
286
+ themeController.change(normalizedThemeName);
287
287
  return true;
288
288
  }
289
289
 
@@ -310,7 +310,7 @@ function setVuetifyPrimaryColorOverride(themeController, themeInput = null) {
310
310
  changed = upsertThemeDefinition(themeDefinitions, WORKSPACE_THEME_NAME_LIGHT, nextLightTheme) || changed;
311
311
  changed = upsertThemeDefinition(themeDefinitions, WORKSPACE_THEME_NAME_DARK, nextDarkTheme) || changed;
312
312
  if (themeController.global.name.value !== nextThemeName) {
313
- themeController.global.name.value = nextThemeName;
313
+ themeController.change(nextThemeName);
314
314
  changed = true;
315
315
  }
316
316
 
@@ -169,7 +169,7 @@ function createBootstrapPlacementRouteGuards({
169
169
  return null;
170
170
  }
171
171
 
172
- function resolveSurfaceAccessGuardDecision(pathname = "/", search = "", { allowOnUnknown = true } = {}) {
172
+ function resolveSurfaceAccessGuardDecision(pathname = "/", search = "") {
173
173
  const surfaceState = resolveSurfaceRouteState(pathname, search);
174
174
  if (!surfaceState) {
175
175
  return null;
@@ -186,7 +186,9 @@ function createBootstrapPlacementRouteGuards({
186
186
  context: placementRuntime.getContext(),
187
187
  surfaceId: surfaceState.surfaceId,
188
188
  workspaceSlug: surfaceState.workspaceSlug,
189
- allowOnUnknown
189
+ // A workspace the person isn't listed in stays pending until the server says
190
+ // not_found or forbidden, so the surface can show that state.
191
+ allowOnUnknown: true
190
192
  });
191
193
  if (accessDecision.allowed || accessDecision.pending) {
192
194
  return null;
@@ -262,9 +264,7 @@ function createBootstrapPlacementRouteGuards({
262
264
  const currentRoute = router.currentRoute?.value || {};
263
265
  const currentPath = resolveRuntimePathname(currentRoute.path || "/");
264
266
  const currentSearch = resolveSearchFromFullPath(currentRoute.fullPath || "");
265
- const surfaceDecision = resolveSurfaceAccessGuardDecision(currentPath, currentSearch, {
266
- allowOnUnknown: false
267
- });
267
+ const surfaceDecision = resolveSurfaceAccessGuardDecision(currentPath, currentSearch);
268
268
  if (!surfaceDecision || !surfaceDecision.redirectTo) {
269
269
  return;
270
270
  }
@@ -306,9 +306,7 @@ function createBootstrapPlacementRouteGuards({
306
306
  return workspaceDecision;
307
307
  }
308
308
 
309
- const surfaceDecision = resolveSurfaceAccessGuardDecision(pathname, search, {
310
- allowOnUnknown: true
311
- });
309
+ const surfaceDecision = resolveSurfaceAccessGuardDecision(pathname, search);
312
310
  if (surfaceDecision) {
313
311
  return surfaceDecision;
314
312
  }
@@ -2,6 +2,7 @@ import {
2
2
  findWorkspaceBySlug,
3
3
  normalizeWorkspaceList
4
4
  } from "../lib/bootstrap.js";
5
+ import { writeLastWorkspaceSlug } from "../lib/lastWorkspace.js";
5
6
  import { normalizePermissionList } from "@jskit-ai/http-web/client/lib/permissions";
6
7
  import {
7
8
  persistBootstrapThemePreference,
@@ -316,19 +317,15 @@ function createBootstrapPlacementRuntime({
316
317
  return payload;
317
318
  }
318
319
 
319
- const requestedWorkspaceStatus = resolveRequestedWorkspaceBootstrapStatus(payload, stateAtApply.workspaceSlug);
320
- if (requestedWorkspaceStatus) {
321
- setWorkspaceBootstrapStatus(stateAtApply.workspaceSlug, requestedWorkspaceStatus, normalizedSource);
322
- return payload;
320
+ const workspaceStatus =
321
+ resolveRequestedWorkspaceBootstrapStatus(payload, stateAtApply.workspaceSlug) ||
322
+ (findWorkspaceBySlug(payload?.workspaces, stateAtApply.workspaceSlug)
323
+ ? WORKSPACE_BOOTSTRAP_STATUS_RESOLVED
324
+ : WORKSPACE_BOOTSTRAP_STATUS_FORBIDDEN);
325
+ setWorkspaceBootstrapStatus(stateAtApply.workspaceSlug, workspaceStatus, normalizedSource);
326
+ if (workspaceStatus === WORKSPACE_BOOTSTRAP_STATUS_RESOLVED) {
327
+ writeLastWorkspaceSlug(payload?.session?.userId, stateAtApply.workspaceSlug);
323
328
  }
324
-
325
- const availableWorkspaces = normalizeWorkspaceList(payload?.workspaces);
326
- const currentWorkspace = findWorkspaceBySlug(availableWorkspaces, stateAtApply.workspaceSlug);
327
- setWorkspaceBootstrapStatus(
328
- stateAtApply.workspaceSlug,
329
- currentWorkspace ? WORKSPACE_BOOTSTRAP_STATUS_RESOLVED : WORKSPACE_BOOTSTRAP_STATUS_FORBIDDEN,
330
- normalizedSource
331
- );
332
329
  return payload;
333
330
  }
334
331
 
@@ -2,6 +2,7 @@ import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
3
  import { resolveWorkspaceThemePalette } from "@jskit-ai/workspaces-core/shared/settings";
4
4
  import { ThemeSymbol } from "vuetify/lib/composables/theme.js";
5
+ import { createVuetifyThemeController } from "./support/vuetifyThemeController.js";
5
6
  import {
6
7
  WORKSPACE_BOOTSTRAP_STATUS_FORBIDDEN,
7
8
  WORKSPACE_BOOTSTRAP_STATUS_NOT_FOUND,
@@ -199,40 +200,6 @@ function createTestRuntime({
199
200
  });
200
201
  }
201
202
 
202
- function createVuetifyThemeController(initial = "light") {
203
- return {
204
- global: {
205
- name: {
206
- value: initial
207
- }
208
- },
209
- themes: {
210
- value: {
211
- light: {
212
- dark: false,
213
- colors: {
214
- primary: "#0f6b54",
215
- secondary: "#3f5150",
216
- background: "#eef3ee",
217
- surface: "#f7fbf6",
218
- "surface-variant": "#dfe8df"
219
- }
220
- },
221
- dark: {
222
- dark: true,
223
- colors: {
224
- primary: "#6fd0b5",
225
- secondary: "#9db2af",
226
- background: "#0f1715",
227
- surface: "#16211e",
228
- "surface-variant": "#253430"
229
- }
230
- }
231
- }
232
- }
233
- };
234
- }
235
-
236
203
  function createVueAppWithThemeController(themeController) {
237
204
  return {
238
205
  _context: {
@@ -319,6 +286,37 @@ test("bootstrap placement runtime contributes workspace slug to shared bootstrap
319
286
  assert.equal(context.pendingInvitesCount, 2);
320
287
  });
321
288
 
289
+ test("bootstrap placement runtime remembers the last workspace each user opened in this browser", async (context) => {
290
+ const stored = new Map();
291
+ globalThis.window = {
292
+ localStorage: {
293
+ getItem: (key) => stored.get(key) ?? null,
294
+ setItem: (key, value) => stored.set(key, String(value))
295
+ }
296
+ };
297
+ context.after(() => {
298
+ delete globalThis.window;
299
+ });
300
+ const placementRuntime = createPlacementRuntimeStub();
301
+ const router = createRouterStub("/w/acme");
302
+ const runtime = createTestRuntime({ placementRuntime, router });
303
+ const session = { authenticated: true, userId: "7" };
304
+ const workspaces = [{ id: "1", slug: "acme", name: "Acme Workspace" }];
305
+
306
+ await runtime.initialize();
307
+ await runtime.applyBootstrapPayload({
308
+ request: createBootstrapRequest("/w/acme", "acme"),
309
+ payload: { session, workspaces, requestedWorkspace: { slug: "acme", status: "resolved" }, permissions: [] }
310
+ });
311
+ await router.push("/w/missing");
312
+ await runtime.applyBootstrapPayload({
313
+ request: createBootstrapRequest("/w/missing", "missing"),
314
+ payload: { session, workspaces, requestedWorkspace: { slug: "missing", status: "not_found" }, permissions: [] }
315
+ });
316
+
317
+ assert.equal(stored.get("jskit.workspaces-web.last-workspace.7"), "acme");
318
+ });
319
+
322
320
  test("bootstrap placement runtime resolves workspace slug from pathname when surface config is missing", async () => {
323
321
  const placementRuntime = createPlacementRuntimeStub();
324
322
  placementRuntime.setContext({}, { replace: true, source: "test.clear" });
@@ -596,7 +594,7 @@ test("bootstrap placement runtime tracks status per workspace slug across route
596
594
  assert.deepEqual(bootstrapRuntime.calls, ["route"]);
597
595
 
598
596
  await runtime.handleBootstrapError({
599
- request: createBootstrapRequest("/w/zen", "zen"),
597
+ request: createBootstrapRequest("/w/zen/dashboard", "zen"),
600
598
  error: createErrorWithStatus(404, "Workspace not found.")
601
599
  });
602
600
 
@@ -683,6 +681,41 @@ test("bootstrap placement runtime uses requestedWorkspace=not_found without forc
683
681
  assert.equal(context.workspaces[0]?.slug, "acme");
684
682
  });
685
683
 
684
+ test("bootstrap placement runtime stays on an unknown workspace URL until the server reports its status", async () => {
685
+ for (const status of [WORKSPACE_BOOTSTRAP_STATUS_NOT_FOUND, WORKSPACE_BOOTSTRAP_STATUS_FORBIDDEN]) {
686
+ const placementRuntime = createPlacementRuntimeStub();
687
+ placementRuntime.setContext({
688
+ surfaceConfig: {
689
+ ...placementRuntime.getContext().surfaceConfig,
690
+ defaultSurfaceId: "home"
691
+ }
692
+ });
693
+ const router = createRouterStub("/w/acme");
694
+ const runtime = createTestRuntime({ placementRuntime, router });
695
+ const session = { authenticated: true, userId: "1" };
696
+ const workspaces = [{ id: "1", slug: "acme", name: "Acme Workspace" }];
697
+
698
+ await runtime.initialize();
699
+ await runtime.applyBootstrapPayload({
700
+ request: createBootstrapRequest("/w/acme", "acme"),
701
+ payload: { session, workspaces, permissions: [] }
702
+ });
703
+ await router.push("/w/missing");
704
+ await runtime.applyBootstrapPayload({
705
+ request: createBootstrapRequest("/w/missing", "missing"),
706
+ payload: {
707
+ session,
708
+ workspaces,
709
+ requestedWorkspace: { slug: "missing", status },
710
+ permissions: []
711
+ }
712
+ });
713
+
714
+ assert.equal(runtime.getWorkspaceBootstrapStatus("missing"), status);
715
+ assert.deepEqual(router.replaceCalls, ["/w/missing"]);
716
+ }
717
+ });
718
+
686
719
  test("bootstrap placement runtime guard wrapper preserves delegated deny outcomes", async () => {
687
720
  const placementRuntime = createPlacementRuntimeStub();
688
721
  const router = createRouterStub("/w/acme/dashboard");
@@ -17,6 +17,7 @@ test("workspaces-web exports are explicit and aligned with production usage", ()
17
17
  "./client",
18
18
  "./client/components/AccountSettingsInvitesSection",
19
19
  "./client/components/WorkspaceInviteLanding",
20
+ "./client/components/WorkspacesClientElement",
20
21
  "./client/providers/WorkspacesWebClientProvider",
21
22
  "./client/composables/useWorkspaceRouteContext"
22
23
  ]
@@ -0,0 +1,74 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import {
4
+ readLastWorkspaceSlug,
5
+ resolveWorkspaceLandingSlug,
6
+ writeLastWorkspaceSlug
7
+ } from "../src/client/lib/lastWorkspace.js";
8
+
9
+ function createStorageStub() {
10
+ const values = new Map();
11
+ return {
12
+ getItem(key) {
13
+ return values.has(key) ? values.get(key) : null;
14
+ },
15
+ setItem(key, value) {
16
+ values.set(key, String(value));
17
+ },
18
+ values
19
+ };
20
+ }
21
+
22
+ const workspaces = [
23
+ { id: "1", slug: "home", name: "Home" },
24
+ { id: "2", slug: "acme", name: "Acme" }
25
+ ];
26
+
27
+ test("last workspace is remembered per user", () => {
28
+ const storage = createStorageStub();
29
+ writeLastWorkspaceSlug("7", "acme", { storage });
30
+ writeLastWorkspaceSlug("8", "home", { storage });
31
+ writeLastWorkspaceSlug("", "ignored", { storage });
32
+
33
+ assert.equal(readLastWorkspaceSlug("7", { storage }), "acme");
34
+ assert.equal(readLastWorkspaceSlug("8", { storage }), "home");
35
+ assert.equal(readLastWorkspaceSlug("9", { storage }), "");
36
+ assert.equal(storage.values.size, 2);
37
+ });
38
+
39
+ test("last workspace memory tolerates unavailable storage", () => {
40
+ const storage = {
41
+ getItem() {
42
+ throw new Error("blocked");
43
+ },
44
+ setItem() {
45
+ throw new Error("blocked");
46
+ }
47
+ };
48
+
49
+ assert.doesNotThrow(() => writeLastWorkspaceSlug("7", "acme", { storage }));
50
+ assert.equal(readLastWorkspaceSlug("7", { storage }), "");
51
+ assert.equal(readLastWorkspaceSlug("7", { storage: null }), "");
52
+ });
53
+
54
+ test("workspace landing opens the last used workspace, then the only one", () => {
55
+ assert.equal(resolveWorkspaceLandingSlug({ workspaces, lastWorkspaceSlug: "acme" }), "acme");
56
+ assert.equal(resolveWorkspaceLandingSlug({ workspaces, lastWorkspaceSlug: "gone" }), "");
57
+ assert.equal(resolveWorkspaceLandingSlug({ workspaces }), "");
58
+ assert.equal(resolveWorkspaceLandingSlug({ workspaces: [workspaces[1]], lastWorkspaceSlug: "gone" }), "acme");
59
+ assert.equal(resolveWorkspaceLandingSlug({ workspaces: [] }), "");
60
+ });
61
+
62
+ test("workspace landing stays on the list for pending invitations or an inaccessible last workspace", () => {
63
+ assert.equal(
64
+ resolveWorkspaceLandingSlug({ workspaces, pendingInvites: [{ token: "a" }], lastWorkspaceSlug: "acme" }),
65
+ ""
66
+ );
67
+ assert.equal(
68
+ resolveWorkspaceLandingSlug({
69
+ workspaces: [workspaces[0], { ...workspaces[1], isAccessible: false }],
70
+ lastWorkspaceSlug: "acme"
71
+ }),
72
+ ""
73
+ );
74
+ });
@@ -26,6 +26,10 @@ test("workspace surfaces pattern includes settings, invitations, and app-owned i
26
26
  path.join(exampleRoot, "src", "pages", "invite", "[token].vue"),
27
27
  "utf8"
28
28
  );
29
+ const workspacesPage = await readFile(
30
+ path.join(exampleRoot, "src", "pages", "home", "workspaces", "index.vue"),
31
+ "utf8"
32
+ );
29
33
 
30
34
  assert.match(settings, /target="admin-settings:primary-menu"/);
31
35
  assert.match(settings, /<RouterView \/>/);
@@ -34,6 +38,8 @@ test("workspace surfaces pattern includes settings, invitations, and app-owned i
34
38
  assert.match(invitationPage, /@jskit-ai\/workspaces-web\/client\/components\/WorkspaceInviteLanding/);
35
39
  assert.match(invitationPage, /<WorkspaceInviteLanding \/>/);
36
40
  assert.doesNotMatch(invitationPage, /\bfetch\s*\(/);
41
+ assert.match(workspacesPage, /@jskit-ai\/workspaces-web\/client\/components\/WorkspacesClientElement/);
42
+ assert.match(workspacesPage, /<WorkspacesClientElement \/>/);
37
43
  });
38
44
 
39
45
  test("workspace settings and not-found examples use direct panels", async () => {
@@ -0,0 +1,51 @@
1
+ import { ThemeSymbol } from "vuetify/lib/composables/theme.js";
2
+
3
+ function createVuetifyThemeController(initialTheme = "light") {
4
+ let themeName = initialTheme;
5
+ return {
6
+ global: {
7
+ name: {
8
+ get value() {
9
+ return themeName;
10
+ },
11
+ set value(_themeName) {
12
+ throw new Error("Vuetify deprecates assigning theme.global.name.value; use theme.change().");
13
+ }
14
+ }
15
+ },
16
+ change(nextThemeName) {
17
+ themeName = nextThemeName;
18
+ },
19
+ themes: {
20
+ value: {
21
+ light: {
22
+ dark: false,
23
+ colors: {
24
+ primary: "#0f6b54",
25
+ secondary: "#3f5150",
26
+ background: "#eef3ee",
27
+ surface: "#f7fbf6",
28
+ "surface-variant": "#dfe8df"
29
+ }
30
+ },
31
+ dark: {
32
+ dark: true,
33
+ colors: {
34
+ primary: "#6fd0b5",
35
+ secondary: "#9db2af",
36
+ background: "#0f1715",
37
+ surface: "#16211e",
38
+ "surface-variant": "#253430"
39
+ }
40
+ }
41
+ }
42
+ },
43
+ _context: {
44
+ provides: {
45
+ [ThemeSymbol]: null
46
+ }
47
+ }
48
+ };
49
+ }
50
+
51
+ export { createVuetifyThemeController };
@@ -1,51 +1,12 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
- import { ThemeSymbol } from "vuetify/lib/composables/theme.js";
4
3
  import { resolveWorkspaceThemePalette } from "@jskit-ai/workspaces-core/shared/settings";
5
4
  import {
6
5
  hexColorToRgb,
7
6
  setVuetifyPrimaryColorOverride,
8
7
  setVuetifyThemeName
9
8
  } from "../src/client/lib/theme.js";
10
-
11
- function createVuetifyThemeController(initialTheme = "light") {
12
- return {
13
- global: {
14
- name: {
15
- value: initialTheme
16
- }
17
- },
18
- themes: {
19
- value: {
20
- light: {
21
- dark: false,
22
- colors: {
23
- primary: "#0f6b54",
24
- secondary: "#3f5150",
25
- background: "#eef3ee",
26
- surface: "#f7fbf6",
27
- "surface-variant": "#dfe8df"
28
- }
29
- },
30
- dark: {
31
- dark: true,
32
- colors: {
33
- primary: "#6fd0b5",
34
- secondary: "#9db2af",
35
- background: "#0f1715",
36
- surface: "#16211e",
37
- "surface-variant": "#253430"
38
- }
39
- }
40
- }
41
- },
42
- _context: {
43
- provides: {
44
- [ThemeSymbol]: null
45
- }
46
- }
47
- };
48
- }
9
+ import { createVuetifyThemeController } from "./support/vuetifyThemeController.js";
49
10
 
50
11
  test("hexColorToRgb returns Vuetify rgb tuple and rejects invalid values", () => {
51
12
  assert.equal(hexColorToRgb("#0f6b54"), "15,107,84");
@@ -0,0 +1,114 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { fileURLToPath } from "node:url";
4
+ import { chromium, expect } from "@playwright/test";
5
+ import { createChromiumLaunchOptions, startViteFixture, stopProcess } from "../../../tooling/testUtils/browserFixture.mjs";
6
+
7
+ const VIEWPORTS = [
8
+ { name: "compact", width: 390, height: 844 },
9
+ { name: "medium", width: 720, height: 1000 },
10
+ { name: "expanded", width: 1280, height: 900 }
11
+ ];
12
+
13
+ function createDeferred() {
14
+ let resolve;
15
+ const promise = new Promise((done) => {
16
+ resolve = done;
17
+ });
18
+ return { promise, resolve };
19
+ }
20
+
21
+ test("Your workspaces keeps its layout while responding and then opens the last workspace", {
22
+ skip: process.env.JSKIT_WORKSPACES_LANDING_BROWSER !== "1",
23
+ timeout: 180_000
24
+ }, async () => {
25
+ const runtime = await startViteFixture({ fixtureRoot: fileURLToPath(new URL("../fixtures/workspaces-landing/", import.meta.url)) });
26
+ let browser;
27
+ let page;
28
+ try {
29
+ browser = await chromium.launch(createChromiumLaunchOptions());
30
+ for (const viewport of VIEWPORTS) {
31
+ page = await browser.newPage({ baseURL: runtime.baseURL, viewport });
32
+ page.setDefaultTimeout(15_000);
33
+ page.setDefaultNavigationTimeout(60_000);
34
+ const errors = [];
35
+ page.on("pageerror", (error) => errors.push(error.message));
36
+ const redeem = createDeferred();
37
+ const refreshStarted = createDeferred();
38
+ const refresh = createDeferred();
39
+ let bootstrapRequests = 0;
40
+ let pendingInvites = [
41
+ { id: "5", workspaceId: "3", workspaceSlug: "zen", workspaceName: "Zen", token: "invite-token", roleSid: "member" }
42
+ ];
43
+ await page.route("**/api/**", async (route) => {
44
+ const path = new URL(route.request().url()).pathname;
45
+ if (path === "/api/session") {
46
+ await route.fulfill({ json: { csrfToken: "fixture-csrf" } });
47
+ return;
48
+ }
49
+ if (path === "/api/workspace/invitations/redeem") {
50
+ await redeem.promise;
51
+ pendingInvites = [];
52
+ await route.fulfill({
53
+ contentType: "application/vnd.api+json",
54
+ json: { data: { type: "workspace-invitation-decisions", id: "5", attributes: { decision: "refuse" } } }
55
+ });
56
+ return;
57
+ }
58
+ bootstrapRequests += 1;
59
+ if (bootstrapRequests > 1) {
60
+ refreshStarted.resolve();
61
+ await refresh.promise;
62
+ }
63
+ await route.fulfill({
64
+ json: {
65
+ session: { authenticated: true, userId: "7" },
66
+ tenancy: { mode: "workspaces", workspace: { allowSelfCreate: true } },
67
+ app: { features: { workspaceInvites: true } },
68
+ workspaces: [
69
+ { id: "1", slug: "home", name: "Home", roleSid: "owner" },
70
+ { id: "2", slug: "acme", name: "Acme", roleSid: "member" }
71
+ ],
72
+ pendingInvites
73
+ }
74
+ });
75
+ });
76
+ await page.addInitScript(() => {
77
+ localStorage.setItem("jskit.workspaces-web.last-workspace.7", "acme");
78
+ });
79
+
80
+ await page.goto("/home/workspaces");
81
+ const heading = page.getByText("Workspaces", { exact: true });
82
+ await page.getByRole("button", { name: "Refuse", exact: true }).waitFor();
83
+ assert.equal(
84
+ await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth),
85
+ 0,
86
+ `${viewport.name}: no horizontal scroll`
87
+ );
88
+ const buttonHeights = await page.locator(".workspaces-view__body .v-btn").evaluateAll(
89
+ (buttons) => buttons.map((button) => button.getBoundingClientRect().height)
90
+ );
91
+ assert.ok(buttonHeights.every((height) => height >= 48), `${viewport.name}: 48px targets, got ${buttonHeights}`);
92
+ const headingBox = await heading.boundingBox();
93
+
94
+ await page.getByRole("button", { name: "Refuse", exact: true }).click();
95
+ await expect(page.getByRole("button", { name: "Refusing…", exact: true })).toBeDisabled();
96
+ redeem.resolve();
97
+ await refreshStarted.promise;
98
+ assert.equal(await page.locator(".v-progress-linear, .v-progress-circular").count(), 0);
99
+ assert.deepEqual(await heading.boundingBox(), headingBox, `${viewport.name}: heading stays put while refreshing`);
100
+
101
+ refresh.resolve();
102
+ await page.getByText("Opened acme", { exact: true }).waitFor();
103
+ assert.deepEqual(errors, []);
104
+ await page.close();
105
+ page = null;
106
+ }
107
+ } catch (error) {
108
+ console.error(await page?.locator("body").innerText());
109
+ throw error;
110
+ } finally {
111
+ if (browser) await browser.close();
112
+ await stopProcess(runtime);
113
+ }
114
+ });