@jskit-ai/workspaces-web 0.2.9 → 0.2.11

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.
Files changed (39) hide show
  1. package/fixtures/workspaces-components/index.html +2 -0
  2. package/fixtures/workspaces-components/main.js +90 -0
  3. package/fixtures/workspaces-components/vite.config.mjs +9 -0
  4. package/package.json +8 -8
  5. package/patterns/workspace-surfaces/example/src/composables/useWorkspaceNotFoundState.js +2 -2
  6. package/src/client/account-settings/accountSettingsInvitesRuntime.js +25 -7
  7. package/src/client/account-settings/useAccountSettingsInvitesSectionRuntime.js +11 -54
  8. package/src/client/browser.js +54 -0
  9. package/src/client/components/MembersAdminClientElement.vue +41 -111
  10. package/src/client/components/WorkspaceMembersClientElement.vue +17 -701
  11. package/src/client/components/WorkspaceSelector.vue +4 -18
  12. package/src/client/components/WorkspacesClientElement.vue +21 -392
  13. package/src/client/composables/useWorkspaceMembersActions.js +309 -0
  14. package/src/client/composables/useWorkspaceMembersPage.js +401 -0
  15. package/src/client/composables/useWorkspaceRouteContext.js +8 -3
  16. package/src/client/composables/useWorkspaceSurfaceId.js +15 -17
  17. package/src/client/composables/useWorkspacesLanding.js +386 -0
  18. package/src/client/lib/bootstrap.js +4 -9
  19. package/src/client/lib/lastWorkspace.js +7 -19
  20. package/src/client/lib/pendingInvites.js +53 -0
  21. package/src/client/lib/profileSurfaceMenuLinks.js +6 -5
  22. package/src/client/lib/surfaceAccessPolicy.js +18 -32
  23. package/src/client/lib/theme.js +8 -69
  24. package/src/client/lib/workspaceLinkResolver.js +9 -2
  25. package/src/client/lib/workspaceMembersPayloads.js +98 -0
  26. package/src/client/lib/workspaceSurfacePaths.js +3 -8
  27. package/src/client/providers/WorkspacesWebClientProvider.js +23 -22
  28. package/src/client/runtime/bootstrapPlacementRouteGuards.js +44 -41
  29. package/src/client/runtime/bootstrapPlacementRuntime.js +49 -76
  30. package/src/client/runtime/bootstrapPlacementRuntimeHelpers.js +6 -12
  31. package/src/client/support/realtimeWorkspace.js +6 -2
  32. package/src/client/support/runtimeNormalization.js +1 -8
  33. package/src/client/support/workspaceScopeSupport.js +10 -7
  34. package/src/client/types.js +168 -0
  35. package/test/bootstrapPlacementRuntime.test.js +25 -1
  36. package/test/pendingInvites.test.js +34 -0
  37. package/test/settingsPlacementContract.test.js +7 -3
  38. package/test/workspaceMembersPayloads.test.js +52 -0
  39. package/test/workspacesComponents.browser.test.js +285 -0
@@ -1,9 +1,7 @@
1
1
  import { resolveSurfaceDefinitionFromPlacementContext } from "@jskit-ai/shell-web/client/placement";
2
+ import { normalizeLowerText, normalizeObject } from "@jskit-ai/kernel/shared/support/normalize";
2
3
  import { normalizeSurfaceId } from "@jskit-ai/kernel/shared/surface/registry";
3
- import {
4
- normalizeRecord,
5
- normalizeWorkspaceBootstrapStatusValue
6
- } from "../support/runtimeNormalization.js";
4
+ import { normalizeWorkspaceBootstrapStatusValue } from "../support/runtimeNormalization.js";
7
5
  import {
8
6
  hasPermission,
9
7
  normalizePermissionList
@@ -16,18 +14,6 @@ const WORKSPACE_ACCESS_BLOCKING_STATUSES = new Set([
16
14
  WORKSPACE_BOOTSTRAP_STATUS_FORBIDDEN
17
15
  ]);
18
16
 
19
- function normalizeSurfaceAccessPolicyId(value = "") {
20
- return String(value || "")
21
- .trim()
22
- .toLowerCase();
23
- }
24
-
25
- function normalizeWorkspaceSlug(value = "") {
26
- return String(value || "")
27
- .trim()
28
- .toLowerCase();
29
- }
30
-
31
17
  function normalizeAccessFlagName(value = "") {
32
18
  return String(value || "")
33
19
  .trim()
@@ -49,7 +35,7 @@ function normalizeStringList(value) {
49
35
  }
50
36
 
51
37
  function normalizeSurfaceAccessFlags(value = null) {
52
- const source = normalizeRecord(value);
38
+ const source = normalizeObject(value);
53
39
  const flags = {};
54
40
 
55
41
  for (const [candidateKey, candidateValue] of Object.entries(source)) {
@@ -83,19 +69,19 @@ function hasKnownSurfaceAccessContext(contextValue = null) {
83
69
  }
84
70
 
85
71
  function hasWorkspaceMembership(contextValue = null, workspaceSlug = "") {
86
- const normalizedWorkspaceSlug = normalizeWorkspaceSlug(workspaceSlug);
72
+ const normalizedWorkspaceSlug = normalizeLowerText(workspaceSlug);
87
73
  if (!normalizedWorkspaceSlug) {
88
74
  return false;
89
75
  }
90
76
 
91
- const context = normalizeRecord(contextValue);
92
- if (normalizeWorkspaceSlug(context?.workspace?.slug) === normalizedWorkspaceSlug) {
77
+ const context = normalizeObject(contextValue);
78
+ if (normalizeLowerText(context?.workspace?.slug) === normalizedWorkspaceSlug) {
93
79
  return true;
94
80
  }
95
81
 
96
82
  const workspaces = Array.isArray(context.workspaces) ? context.workspaces : [];
97
83
  for (const workspace of workspaces) {
98
- if (normalizeWorkspaceSlug(workspace?.slug) === normalizedWorkspaceSlug) {
84
+ if (normalizeLowerText(workspace?.slug) === normalizedWorkspaceSlug) {
99
85
  return true;
100
86
  }
101
87
  }
@@ -104,26 +90,26 @@ function hasWorkspaceMembership(contextValue = null, workspaceSlug = "") {
104
90
  }
105
91
 
106
92
  function resolveSurfaceAccessPolicies(contextValue = null) {
107
- const context = normalizeRecord(contextValue);
108
- const configuredPolicies = normalizeRecord(context.surfaceAccessPolicies);
93
+ const context = normalizeObject(contextValue);
94
+ const configuredPolicies = normalizeObject(context.surfaceAccessPolicies);
109
95
  const policies = {};
110
96
 
111
97
  for (const [candidatePolicyId, candidatePolicy] of Object.entries(configuredPolicies)) {
112
- const policyId = normalizeSurfaceAccessPolicyId(candidatePolicyId);
98
+ const policyId = normalizeLowerText(candidatePolicyId);
113
99
  if (!policyId) {
114
100
  continue;
115
101
  }
116
- policies[policyId] = normalizeRecord(candidatePolicy);
102
+ policies[policyId] = normalizeObject(candidatePolicy);
117
103
  }
118
104
 
119
105
  return policies;
120
106
  }
121
107
 
122
108
  function resolveSurfaceAccessPolicy(contextValue = null, surfaceDefinition = null) {
123
- const definition = normalizeRecord(surfaceDefinition);
124
- const policyId = normalizeSurfaceAccessPolicyId(definition.accessPolicyId);
109
+ const definition = normalizeObject(surfaceDefinition);
110
+ const policyId = normalizeLowerText(definition.accessPolicyId);
125
111
  const configuredPolicies = resolveSurfaceAccessPolicies(contextValue);
126
- const configuredPolicy = policyId ? normalizeRecord(configuredPolicies[policyId]) : {};
112
+ const configuredPolicy = policyId ? normalizeObject(configuredPolicies[policyId]) : {};
127
113
 
128
114
  const requireAuth = Object.hasOwn(configuredPolicy, "requireAuth")
129
115
  ? configuredPolicy.requireAuth === true
@@ -218,7 +204,7 @@ function evaluateSurfaceAccess({
218
204
  workspaceSlug = "",
219
205
  allowOnUnknown = false
220
206
  } = {}) {
221
- const source = normalizeRecord(context);
207
+ const source = normalizeObject(context);
222
208
  const normalizedSurfaceId = normalizeSurfaceId(surfaceId);
223
209
  if (!normalizedSurfaceId) {
224
210
  return toAccessDecision({
@@ -243,7 +229,7 @@ function evaluateSurfaceAccess({
243
229
  });
244
230
  }
245
231
 
246
- const normalizedWorkspaceSlug = normalizeWorkspaceSlug(workspaceSlug);
232
+ const normalizedWorkspaceSlug = normalizeLowerText(workspaceSlug);
247
233
  if (policy.requireWorkspaceMembership) {
248
234
  if (!normalizedWorkspaceSlug) {
249
235
  return toAccessDecision({
@@ -252,7 +238,7 @@ function evaluateSurfaceAccess({
252
238
  });
253
239
  }
254
240
 
255
- const workspaceBootstrapStatuses = normalizeRecord(source.workspaceBootstrapStatuses);
241
+ const workspaceBootstrapStatuses = normalizeObject(source.workspaceBootstrapStatuses);
256
242
  const workspaceStatus = normalizeWorkspaceBootstrapStatusValue(
257
243
  workspaceBootstrapStatuses[normalizedWorkspaceSlug],
258
244
  WORKSPACE_ACCESS_BLOCKING_STATUSES
@@ -334,7 +320,7 @@ function evaluateSurfaceAccess({
334
320
  });
335
321
  }
336
322
 
337
- const accessFlags = normalizeRecord(source.surfaceAccess);
323
+ const accessFlags = normalizeObject(source.surfaceAccess);
338
324
  const flagDecision = evaluateFlagRequirements(policy, accessFlags);
339
325
  if (!flagDecision.allowed) {
340
326
  return flagDecision;
@@ -1,5 +1,6 @@
1
1
  import { ThemeSymbol } from "vuetify/lib/composables/theme.js";
2
2
  import { resolveWorkspaceThemePalette } from "@jskit-ai/workspaces-core/shared/settings";
3
+ import { pageLocalStorage, pagePrefersDark } from "../browser.js";
3
4
 
4
5
  const THEME_PREFERENCE_LIGHT = "light";
5
6
  const THEME_PREFERENCE_DARK = "dark";
@@ -17,16 +18,8 @@ function normalizeThemePreference(value) {
17
18
  }
18
19
 
19
20
  function resolveSystemThemeName({ prefersDark } = {}) {
20
- if (typeof prefersDark === "boolean") {
21
- return prefersDark ? THEME_PREFERENCE_DARK : THEME_PREFERENCE_LIGHT;
22
- }
23
-
24
- if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
25
- const prefersDarkFromMedia = window.matchMedia("(prefers-color-scheme: dark)").matches;
26
- return prefersDarkFromMedia ? THEME_PREFERENCE_DARK : THEME_PREFERENCE_LIGHT;
27
- }
28
-
29
- return THEME_PREFERENCE_LIGHT;
21
+ const dark = typeof prefersDark === "boolean" ? prefersDark : pagePrefersDark();
22
+ return dark ? THEME_PREFERENCE_DARK : THEME_PREFERENCE_LIGHT;
30
23
  }
31
24
 
32
25
  function resolveThemeNameForPreference(themePreference, options = {}) {
@@ -41,31 +34,8 @@ function resolveThemeNameForPreference(themePreference, options = {}) {
41
34
  return resolveSystemThemeName(options);
42
35
  }
43
36
 
44
- function resolveThemePreferenceStorage(options = {}) {
45
- const customStorage = options && typeof options === "object" ? options.storage : null;
46
- if (customStorage && typeof customStorage === "object") {
47
- return customStorage;
48
- }
49
-
50
- if (typeof window !== "object" || !window) {
51
- return null;
52
- }
53
-
54
- let storage = null;
55
- try {
56
- storage = window.localStorage;
57
- } catch {
58
- return null;
59
- }
60
- if (!storage || typeof storage !== "object") {
61
- return null;
62
- }
63
- return storage;
64
- }
65
-
66
- function readPersistedThemePreference(options = {}) {
67
- const storage = resolveThemePreferenceStorage(options);
68
- if (!storage || typeof storage.getItem !== "function") {
37
+ function readPersistedThemePreference({ storage = pageLocalStorage() } = {}) {
38
+ if (!storage) {
69
39
  return THEME_PREFERENCE_SYSTEM;
70
40
  }
71
41
 
@@ -77,9 +47,8 @@ function readPersistedThemePreference(options = {}) {
77
47
  }
78
48
  }
79
49
 
80
- function persistThemePreference(themePreference, options = {}) {
81
- const storage = resolveThemePreferenceStorage(options);
82
- if (!storage || typeof storage.setItem !== "function") {
50
+ function persistThemePreference(themePreference, { storage = pageLocalStorage() } = {}) {
51
+ if (!storage) {
83
52
  return false;
84
53
  }
85
54
 
@@ -118,16 +87,7 @@ function persistBootstrapThemePreference(payload = {}, options = {}) {
118
87
  }
119
88
 
120
89
  function resolveVuetifyThemeController(vueApp) {
121
- if (!vueApp || typeof vueApp !== "object") {
122
- return null;
123
- }
124
-
125
- const provides = vueApp._context?.provides;
126
- if (!provides || typeof provides !== "object") {
127
- return null;
128
- }
129
-
130
- const themeController = provides[ThemeSymbol];
90
+ const themeController = vueApp._context.provides[ThemeSymbol];
131
91
  if (
132
92
  !themeController ||
133
93
  typeof themeController !== "object" ||
@@ -141,15 +101,6 @@ function resolveVuetifyThemeController(vueApp) {
141
101
  }
142
102
 
143
103
  function setVuetifyThemeName(themeController, themeName) {
144
- if (
145
- !themeController ||
146
- typeof themeController !== "object" ||
147
- !themeController.global ||
148
- !themeController.global.name
149
- ) {
150
- return false;
151
- }
152
-
153
104
  const normalizedThemeName = themeName === THEME_PREFERENCE_DARK ? THEME_PREFERENCE_DARK : THEME_PREFERENCE_LIGHT;
154
105
  if (themeController.global.name.value === normalizedThemeName) {
155
106
  return false;
@@ -179,9 +130,6 @@ function hexColorToRgb(value = "") {
179
130
  }
180
131
 
181
132
  function resolveVuetifyThemeDefinitions(themeController) {
182
- if (!themeController || typeof themeController !== "object") {
183
- return null;
184
- }
185
133
  const themes = themeController.themes?.value;
186
134
  if (!themes || typeof themes !== "object") {
187
135
  return null;
@@ -259,15 +207,6 @@ function upsertThemeDefinition(themeDefinitions, themeName, nextDefinition) {
259
207
  }
260
208
 
261
209
  function setVuetifyPrimaryColorOverride(themeController, themeInput = null) {
262
- if (
263
- !themeController ||
264
- typeof themeController !== "object" ||
265
- !themeController.global ||
266
- !themeController.global.name
267
- ) {
268
- return false;
269
- }
270
-
271
210
  const themeDefinitions = resolveVuetifyThemeDefinitions(themeController);
272
211
  if (!themeDefinitions) {
273
212
  return false;
@@ -154,6 +154,13 @@ function resolveWorkspaceShellLinkPath({
154
154
  return resolveLinkPath(nextSurfaceBasePath, nextSurfaceRelativePath);
155
155
  }
156
156
 
157
+ /**
158
+ * Resolves shell links against the placement context.
159
+ * @param {object} [options]
160
+ * @param {import("vue").MaybeRef<string>} [options.surface]
161
+ * @param {import("vue").MaybeRef<string>} [options.workspaceSlug]
162
+ * @param {import("vue").MaybeRef<string>} [options.pathname]
163
+ */
157
164
  function useWorkspaceLinkResolver({ surface = "", workspaceSlug = "", pathname = "" } = {}) {
158
165
  const { context: placementContext } = useWebPlacementContext();
159
166
 
@@ -192,12 +199,12 @@ function useWorkspaceLinkResolver({ surface = "", workspaceSlug = "", pathname =
192
199
  });
193
200
  }
194
201
 
195
- return Object.freeze({
202
+ return {
196
203
  resolve,
197
204
  toSurface,
198
205
  toWorkspace,
199
206
  toAuto
200
- });
207
+ };
201
208
  }
202
209
 
203
210
  export {
@@ -0,0 +1,98 @@
1
+ import { normalizeRecordId } from "@jskit-ai/kernel/shared/support/normalize";
2
+
3
+ function toRoleTitle(roleSid) {
4
+ const normalizedRoleId = String(roleSid || "").trim();
5
+ if (!normalizedRoleId) {
6
+ return "";
7
+ }
8
+ return normalizedRoleId.charAt(0).toUpperCase() + normalizedRoleId.slice(1);
9
+ }
10
+
11
+ function normalizeRoleCatalog(payload) {
12
+ const source =
13
+ payload?.roleCatalog && typeof payload.roleCatalog === "object"
14
+ ? payload.roleCatalog
15
+ : payload && typeof payload === "object"
16
+ ? payload
17
+ : {};
18
+
19
+ const roles = Array.isArray(source.roles) ? source.roles : [];
20
+ const assignableRoleIdsFromCatalog = Array.isArray(source.assignableRoleIds)
21
+ ? source.assignableRoleIds
22
+ : [];
23
+
24
+ let assignableRoleIds = assignableRoleIdsFromCatalog
25
+ .map((entry) => String(entry || "").trim().toLowerCase())
26
+ .filter(Boolean);
27
+
28
+ if (assignableRoleIds.length < 1) {
29
+ assignableRoleIds = roles
30
+ .filter((entry) => entry?.assignable === true)
31
+ .map((entry) => String(entry?.id || "").trim().toLowerCase())
32
+ .filter(Boolean);
33
+ }
34
+
35
+ const uniqueRoleIds = Array.from(new Set(assignableRoleIds));
36
+ const roleLabels = Object.create(null);
37
+ for (const role of roles) {
38
+ const id = String(role?.id || "").trim().toLowerCase();
39
+ const label = typeof role?.label === "string" ? role.label.trim() : "";
40
+ if (id && label) {
41
+ roleLabels[id] = label;
42
+ }
43
+ }
44
+ const roleOptions = uniqueRoleIds.map((roleSid) => ({
45
+ title: roleLabels[roleSid] || toRoleTitle(roleSid),
46
+ value: roleSid
47
+ }));
48
+
49
+ const defaultInviteRole = String(source.defaultInviteRole || "")
50
+ .trim()
51
+ .toLowerCase();
52
+
53
+ return {
54
+ roleOptions,
55
+ roleLabels,
56
+ defaultInviteRole
57
+ };
58
+ }
59
+
60
+ function normalizeMembers(entries) {
61
+ const source = Array.isArray(entries) ? entries : [];
62
+ return source.map((entry) => {
63
+ const value = entry && typeof entry === "object" ? entry : {};
64
+ return {
65
+ userId: normalizeRecordId(value.userId, { fallback: "" }),
66
+ roleSid: String(value.roleSid || "").trim().toLowerCase(),
67
+ status: String(value.status || "").trim().toLowerCase(),
68
+ displayName: String(value.displayName || "").trim(),
69
+ email: String(value.email || "").trim().toLowerCase(),
70
+ isOwner: Boolean(value.isOwner)
71
+ };
72
+ });
73
+ }
74
+
75
+ function normalizeInvites(entries) {
76
+ const source = Array.isArray(entries) ? entries : [];
77
+ return source.map((entry) => {
78
+ const value = entry && typeof entry === "object" ? entry : {};
79
+ return {
80
+ id: normalizeRecordId(value.id, { fallback: "" }),
81
+ email: String(value.email || "").trim().toLowerCase(),
82
+ roleSid: String(value.roleSid || "").trim().toLowerCase(),
83
+ status: String(value.status || "").trim().toLowerCase(),
84
+ expiresAt: value.expiresAt || "",
85
+ invitedByUserId: normalizeRecordId(value.invitedByUserId, { fallback: null })
86
+ };
87
+ });
88
+ }
89
+
90
+ function latestPage(pages) {
91
+ if (!Array.isArray(pages) || pages.length < 1) {
92
+ return null;
93
+ }
94
+
95
+ return pages[pages.length - 1];
96
+ }
97
+
98
+ export { latestPage, normalizeInvites, normalizeMembers, normalizeRoleCatalog };
@@ -14,6 +14,7 @@ import {
14
14
  resolveSurfacePathFromPlacementContext,
15
15
  resolveSurfaceRootPathFromPlacementContext
16
16
  } from "@jskit-ai/shell-web/client/placement";
17
+ import { pagePathname } from "../browser.js";
17
18
  import {
18
19
  listWorkspaceSurfaceIdsFromSurfaceConfig,
19
20
  surfaceRequiresWorkspaceFromPlacementContext
@@ -76,11 +77,7 @@ function resolveWorkspaceSurfaceIdFromSurfaceConfig(surfaceConfig, pathname = ""
76
77
 
77
78
  function resolveWorkspaceSurfaceIdFromPlacementPathname(contextValue = null, pathname = "") {
78
79
  const surfaceConfig = readPlacementSurfaceConfig(contextValue);
79
- const normalizedPathname =
80
- normalizePathname(pathname) ||
81
- (typeof window === "object" && window?.location?.pathname ? normalizePathname(window.location.pathname) : "/");
82
-
83
- return resolveWorkspaceSurfaceIdFromSurfaceConfig(surfaceConfig, normalizedPathname);
80
+ return resolveWorkspaceSurfaceIdFromSurfaceConfig(surfaceConfig, normalizePathname(pathname));
84
81
  }
85
82
 
86
83
  function resolveAccountSettingsPathFromPlacementContext(contextValue = null) {
@@ -131,9 +128,7 @@ function resolveSurfaceWorkspacePathFromPlacementContext(contextValue = null, su
131
128
  }
132
129
 
133
130
  function extractWorkspaceSlugFromSurfacePathname(contextValue = null, surfaceId = "", pathname = "") {
134
- const normalizedPathname = normalizePathname(
135
- pathname || (typeof window === "object" && window?.location?.pathname ? window.location.pathname : "/")
136
- );
131
+ const normalizedPathname = normalizePathname(pathname || pagePathname() || "/");
137
132
  const normalizedSurfaceId = normalizeSurfaceId(surfaceId);
138
133
  if (!normalizedSurfaceId) {
139
134
  return "";
@@ -25,6 +25,15 @@ const WorkspacesWebClientProvider = defineProvider({
25
25
  provides: {
26
26
  workspaces: "client.workspaces"
27
27
  },
28
+ /**
29
+ * @param {object} capabilities
30
+ * @param {import("@jskit-ai/kernel/client/types").ClientComponents} capabilities.components
31
+ * @param {import("@jskit-ai/kernel/client/types").ClientLogger} capabilities.logger
32
+ * @param {import("../types.js").WorkspaceRealtime | null} capabilities.realtime
33
+ * @param {import("@jskit-ai/kernel/client/types").ClientRouter} capabilities.router
34
+ * @param {import("../types.js").WorkspaceShell} capabilities.shell
35
+ * @param {import("@jskit-ai/kernel/client/types").ClientVueApp} capabilities.vueApp
36
+ */
28
37
  setup({ components, logger, realtime, router, shell, vueApp }) {
29
38
  components.register("workspaces.web.profile.menu.surface-switch-item", WorkspaceProfileSurfaceSwitchMenuItem);
30
39
  components.register("workspaces.web.workspace.selector", WorkspaceSelector);
@@ -45,15 +54,9 @@ const WorkspacesWebClientProvider = defineProvider({
45
54
  Object.freeze({
46
55
  handlerId: "workspaces.web.bootstrap",
47
56
  order: 100,
48
- resolveBootstrapRequest(input = {}) {
49
- return runtime.resolveBootstrapRequest(input);
50
- },
51
- applyBootstrapPayload(input = {}) {
52
- return runtime.applyBootstrapPayload(input);
53
- },
54
- handleBootstrapError(input = {}) {
55
- return runtime.handleBootstrapError(input);
56
- }
57
+ resolveBootstrapRequest: runtime.resolveBootstrapRequest,
58
+ applyBootstrapPayload: runtime.applyBootstrapPayload,
59
+ handleBootstrapError: runtime.handleBootstrapError
57
60
  })
58
61
  );
59
62
  return {
@@ -63,26 +66,24 @@ const WorkspacesWebClientProvider = defineProvider({
63
66
  })
64
67
  };
65
68
  },
69
+ /**
70
+ * @param {{ vueApp: import("@jskit-ai/kernel/client/types").ClientVueApp }} capabilities
71
+ * @param {{ outputs: { workspaces: import("../types.js").WorkspacesClient } }} lifecycle
72
+ */
66
73
  async boot({ vueApp }, { outputs }) {
67
- const runtime = outputs.workspaces.bootstrap;
68
- if (runtime && typeof runtime.initialize === "function") {
69
- await runtime.initialize();
70
- }
71
-
72
- if (!vueApp || typeof vueApp.provide !== "function") {
73
- return;
74
- }
74
+ await outputs.workspaces.bootstrap.initialize();
75
75
 
76
76
  vueApp.provide(
77
77
  WORKSPACES_WEB_SCOPE_SUPPORT_INJECTION_KEY,
78
78
  outputs.workspaces.scopeSupport
79
79
  );
80
80
  },
81
- shutdown(_dependencies, { outputs }) {
82
- const runtime = outputs.workspaces.bootstrap;
83
- if (runtime && typeof runtime.shutdown === "function") {
84
- runtime.shutdown();
85
- }
81
+ /**
82
+ * @param {object} _capabilities
83
+ * @param {{ outputs: { workspaces: import("../types.js").WorkspacesClient } }} lifecycle
84
+ */
85
+ shutdown(_capabilities, { outputs }) {
86
+ outputs.workspaces.bootstrap.shutdown();
86
87
  }
87
88
  });
88
89
 
@@ -1,3 +1,4 @@
1
+ import { normalizeLowerText } from "@jskit-ai/kernel/shared/support/normalize";
1
2
  import {
2
3
  resolveSurfaceDefinitionFromPlacementContext,
3
4
  resolveSurfaceIdFromPlacementPathname,
@@ -20,18 +21,37 @@ import {
20
21
  isGuardDenied,
21
22
  normalizeSearch,
22
23
  normalizeWorkspaceBootstrapStatus,
23
- normalizeWorkspaceSlugKey,
24
24
  resolveSearchFromFullPath
25
25
  } from "./bootstrapPlacementRuntimeHelpers.js";
26
26
 
27
+ function allowEveryRoute() {
28
+ return true;
29
+ }
30
+
31
+ /**
32
+ * The evaluator in the shell's guard slot, a page global any package can write: anything but a function counts as none.
33
+ * @param {unknown} candidate
34
+ * @returns {import("../types.js").ShellGuardEvaluator}
35
+ */
36
+ function normalizeGuardEvaluator(candidate) {
37
+ return typeof candidate === "function" ? candidate : allowEveryRoute;
38
+ }
39
+
40
+ /**
41
+ * @param {object} options
42
+ * @param {import("../types.js").WorkspacePlacementRuntime} options.placementRuntime
43
+ * @param {import("@jskit-ai/kernel/client/types").ClientRouter} options.router
44
+ * @param {typeof globalThis} options.root The object holding the shell's guard slot.
45
+ * @param {(workspaceSlug: string) => string} options.getWorkspaceBootstrapStatus
46
+ */
27
47
  function createBootstrapPlacementRouteGuards({
28
48
  placementRuntime,
29
- router = null,
30
- root = null,
31
- getWorkspaceBootstrapStatus = () => ""
32
- } = {}) {
49
+ router,
50
+ root,
51
+ getWorkspaceBootstrapStatus
52
+ }) {
33
53
  const cleanup = [];
34
- let delegatedGuardEvaluator = null;
54
+ let delegatedGuardEvaluator = allowEveryRoute;
35
55
  let workspaceGuardEvaluatorInstalled = false;
36
56
 
37
57
  function resolveNormalizedSurfaceState(pathname = "/", search = "") {
@@ -65,7 +85,7 @@ function createBootstrapPlacementRouteGuards({
65
85
  return null;
66
86
  }
67
87
 
68
- const workspaceSlug = normalizeWorkspaceSlugKey(
88
+ const workspaceSlug = normalizeLowerText(
69
89
  extractWorkspaceSlugFromSurfacePathname(surfaceState.context, surfaceState.surfaceId, surfaceState.normalizedPathname)
70
90
  );
71
91
  if (!workspaceSlug) {
@@ -92,7 +112,7 @@ function createBootstrapPlacementRouteGuards({
92
112
 
93
113
  const workspaceSlug =
94
114
  surfaceState.surfaceDefinition.requiresWorkspace === true
95
- ? normalizeWorkspaceSlugKey(
115
+ ? normalizeLowerText(
96
116
  extractWorkspaceSlugFromSurfacePathname(
97
117
  surfaceState.context,
98
118
  surfaceState.surfaceId,
@@ -122,7 +142,7 @@ function createBootstrapPlacementRouteGuards({
122
142
  const fallbackSurfaceDefinition = resolveSurfaceDefinitionFromPlacementContext(context, fallbackSurfaceId);
123
143
  if (fallbackSurfaceDefinition?.requiresWorkspace === true) {
124
144
  const fallbackWorkspaceSlug =
125
- normalizeWorkspaceSlugKey(surfaceState?.workspaceSlug) || normalizeWorkspaceSlugKey(context?.workspace?.slug);
145
+ normalizeLowerText(surfaceState?.workspaceSlug) || normalizeLowerText(context?.workspace?.slug);
126
146
  if (!fallbackWorkspaceSlug) {
127
147
  return "/";
128
148
  }
@@ -205,16 +225,12 @@ function createBootstrapPlacementRouteGuards({
205
225
  }
206
226
 
207
227
  async function replaceRouteIfNeeded(targetPath = "") {
208
- if (!router || typeof router.replace !== "function") {
209
- return;
210
- }
211
-
212
228
  const normalizedTargetPath = String(targetPath || "").trim();
213
229
  if (!normalizedTargetPath) {
214
230
  return;
215
231
  }
216
232
 
217
- const currentRoute = router.currentRoute?.value || {};
233
+ const currentRoute = router.currentRoute.value;
218
234
  const currentFullPath = String(currentRoute.fullPath || "").trim();
219
235
  const currentPath = resolveRuntimePathname(currentRoute.path || "/");
220
236
  const currentComparablePath = currentFullPath || currentPath;
@@ -228,13 +244,13 @@ function createBootstrapPlacementRouteGuards({
228
244
  }
229
245
 
230
246
  function enforceWorkspaceRouteForStatusUpdate({ workspaceSlug = "", status = "" } = {}) {
231
- const normalizedWorkspaceSlug = normalizeWorkspaceSlugKey(workspaceSlug);
247
+ const normalizedWorkspaceSlug = normalizeLowerText(workspaceSlug);
232
248
  const normalizedStatus = normalizeWorkspaceBootstrapStatus(status);
233
- if (!normalizedWorkspaceSlug || !normalizedStatus || !router) {
249
+ if (!normalizedWorkspaceSlug || !normalizedStatus) {
234
250
  return;
235
251
  }
236
252
 
237
- const currentRoute = router.currentRoute?.value || {};
253
+ const currentRoute = router.currentRoute.value;
238
254
  const currentPath = resolveRuntimePathname(currentRoute.path || "/");
239
255
  const currentSearch = resolveSearchFromFullPath(currentRoute.fullPath || "");
240
256
  const workspaceState = resolveWorkspaceRouteState(currentPath, currentSearch);
@@ -257,11 +273,7 @@ function createBootstrapPlacementRouteGuards({
257
273
  }
258
274
 
259
275
  function enforceSurfaceAccessForCurrentRoute() {
260
- if (!router) {
261
- return;
262
- }
263
-
264
- const currentRoute = router.currentRoute?.value || {};
276
+ const currentRoute = router.currentRoute.value;
265
277
  const currentPath = resolveRuntimePathname(currentRoute.path || "/");
266
278
  const currentSearch = resolveSearchFromFullPath(currentRoute.fullPath || "");
267
279
  const surfaceDecision = resolveSurfaceAccessGuardDecision(currentPath, currentSearch);
@@ -273,28 +285,22 @@ function createBootstrapPlacementRouteGuards({
273
285
  }
274
286
 
275
287
  function installWorkspaceGuardEvaluator() {
276
- if (!root || workspaceGuardEvaluatorInstalled) {
288
+ if (workspaceGuardEvaluatorInstalled) {
277
289
  return;
278
290
  }
279
291
 
280
- if (typeof delegatedGuardEvaluator !== "function") {
281
- const currentEvaluator = root[SHELL_GUARD_EVALUATOR_KEY];
282
- delegatedGuardEvaluator = typeof currentEvaluator === "function" ? currentEvaluator : null;
283
- }
292
+ delegatedGuardEvaluator = normalizeGuardEvaluator(root[SHELL_GUARD_EVALUATOR_KEY]);
284
293
 
285
294
  const previousDescriptor = Object.getOwnPropertyDescriptor(root, SHELL_GUARD_EVALUATOR_KEY);
286
295
  const previousOwnProperty = previousDescriptor || null;
287
296
  let released = false;
288
297
 
289
298
  const workspaceGuardEvaluator = ({ guard, phase, context } = {}) => {
290
- const baseOutcome =
291
- typeof delegatedGuardEvaluator === "function"
292
- ? delegatedGuardEvaluator({
293
- guard,
294
- phase,
295
- context
296
- })
297
- : true;
299
+ const baseOutcome = delegatedGuardEvaluator({
300
+ guard,
301
+ phase,
302
+ context
303
+ });
298
304
  if (isGuardDenied(baseOutcome)) {
299
305
  return baseOutcome;
300
306
  }
@@ -324,13 +330,13 @@ function createBootstrapPlacementRouteGuards({
324
330
  if (nextEvaluator === workspaceGuardEvaluator) {
325
331
  return;
326
332
  }
327
- delegatedGuardEvaluator = typeof nextEvaluator === "function" ? nextEvaluator : null;
333
+ delegatedGuardEvaluator = normalizeGuardEvaluator(nextEvaluator);
328
334
  }
329
335
  });
330
336
  workspaceGuardEvaluatorInstalled = true;
331
337
 
332
338
  cleanup.push(() => {
333
- if (released || !root) {
339
+ if (released) {
334
340
  return;
335
341
  }
336
342
  released = true;
@@ -342,16 +348,13 @@ function createBootstrapPlacementRouteGuards({
342
348
  delete root[SHELL_GUARD_EVALUATOR_KEY];
343
349
  }
344
350
  } catch {}
345
- delegatedGuardEvaluator = null;
351
+ delegatedGuardEvaluator = allowEveryRoute;
346
352
  workspaceGuardEvaluatorInstalled = false;
347
353
  });
348
354
  }
349
355
 
350
356
  function shutdown() {
351
357
  for (const release of cleanup.splice(0, cleanup.length)) {
352
- if (typeof release !== "function") {
353
- continue;
354
- }
355
358
  try {
356
359
  release();
357
360
  } catch {}