@jskit-ai/workspaces-web 0.1.13 → 0.1.15

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 (48) hide show
  1. package/package.descriptor.mjs +61 -25
  2. package/package.json +13 -3
  3. package/src/client/account-settings/accountSettingsInvitesRuntime.js +88 -0
  4. package/src/client/account-settings/useAccountSettingsInvitesSectionRuntime.js +217 -0
  5. package/src/client/components/AccountSettingsInvitesSection.vue +72 -0
  6. package/src/client/components/MembersAdminClientElement.vue +400 -0
  7. package/src/client/components/UsersProfileSurfaceSwitchMenuItem.vue +39 -0
  8. package/src/client/components/UsersWorkspaceMembersMenuItem.vue +36 -0
  9. package/src/client/components/UsersWorkspacePermissionMenuItem.vue +89 -0
  10. package/src/client/components/UsersWorkspaceSelector.vue +242 -0
  11. package/src/client/components/UsersWorkspaceSettingsMenuItem.vue +39 -0
  12. package/src/client/components/UsersWorkspaceToolsWidget.vue +12 -0
  13. package/src/client/components/WorkspaceMembersClientElement.vue +657 -0
  14. package/src/client/components/WorkspaceProfileClientElement.vue +116 -0
  15. package/src/client/components/WorkspaceSettingsClientElement.vue +102 -0
  16. package/src/client/components/WorkspaceSettingsFieldsClientElement.vue +265 -0
  17. package/src/client/components/WorkspacesClientElement.vue +540 -0
  18. package/src/client/composables/useBootstrapQuery.js +52 -0
  19. package/src/client/composables/useWorkspaceRouteContext.js +28 -0
  20. package/src/client/composables/useWorkspaceSurfaceId.js +43 -0
  21. package/src/client/index.js +1 -0
  22. package/src/client/lib/bootstrap.js +59 -0
  23. package/src/client/lib/httpClient.js +10 -0
  24. package/src/client/lib/permissions.js +27 -0
  25. package/src/client/lib/profileSurfaceMenuLinks.js +163 -0
  26. package/src/client/lib/surfaceAccessPolicy.js +350 -0
  27. package/src/client/lib/theme.js +332 -0
  28. package/src/client/lib/workspaceLinkResolver.js +207 -0
  29. package/src/client/lib/workspaceSurfaceContext.js +82 -0
  30. package/src/client/lib/workspaceSurfacePaths.js +163 -0
  31. package/src/client/providers/WorkspacesWebClientProvider.js +59 -2
  32. package/src/client/runtime/bootstrapPlacementRouteGuards.js +371 -0
  33. package/src/client/runtime/bootstrapPlacementRuntime.js +463 -0
  34. package/src/client/runtime/bootstrapPlacementRuntimeConstants.js +28 -0
  35. package/src/client/runtime/bootstrapPlacementRuntimeHelpers.js +147 -0
  36. package/src/client/support/realtimeWorkspace.js +21 -0
  37. package/src/client/support/runtimeNormalization.js +23 -0
  38. package/src/client/support/workspaceQueryKeys.js +15 -0
  39. package/src/shared/toolsOutletContracts.js +9 -0
  40. package/templates/src/pages/admin/members/index.vue +1 -1
  41. package/test/bootstrapPlacementRuntime.test.js +1095 -0
  42. package/test/exportsContract.test.js +2 -1
  43. package/test/profileSurfaceMenuLinks.test.js +208 -0
  44. package/test/settingsPlacementContract.test.js +19 -1
  45. package/test/surfaceAccessPolicy.test.js +129 -0
  46. package/test/theme.test.js +101 -0
  47. package/test/workspaceLinkResolver.test.js +61 -0
  48. package/test/workspaceSurfacePaths.test.js +39 -0
@@ -0,0 +1,59 @@
1
+ import { normalizeLowerText, normalizeText } from "@jskit-ai/kernel/shared/actions/textNormalization";
2
+ import { normalizeRecordId } from "@jskit-ai/kernel/shared/support/normalize";
3
+
4
+ function normalizeWorkspaceSlug(value = "") {
5
+ return normalizeLowerText(value);
6
+ }
7
+
8
+ function normalizeWorkspaceEntry(entry = null) {
9
+ if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
10
+ return null;
11
+ }
12
+
13
+ const id = normalizeRecordId(entry.id, { fallback: "" });
14
+ const slug = normalizeWorkspaceSlug(entry.slug);
15
+ const name = normalizeText(entry.name);
16
+ if (!id || !slug || !name) {
17
+ return null;
18
+ }
19
+
20
+ return Object.freeze({
21
+ id,
22
+ slug,
23
+ name,
24
+ avatarUrl: normalizeText(entry.avatarUrl),
25
+ roleSid: normalizeLowerText(entry.roleSid || "member") || "member",
26
+ isAccessible: entry.isAccessible !== false
27
+ });
28
+ }
29
+
30
+ function normalizeWorkspaceList(entries = []) {
31
+ if (!Array.isArray(entries)) {
32
+ return [];
33
+ }
34
+
35
+ return entries.map((entry) => normalizeWorkspaceEntry(entry)).filter(Boolean);
36
+ }
37
+
38
+ function findWorkspaceBySlug(entries = [], workspaceSlug = "") {
39
+ const normalizedWorkspaceSlug = normalizeWorkspaceSlug(workspaceSlug);
40
+ if (!normalizedWorkspaceSlug) {
41
+ return null;
42
+ }
43
+
44
+ return normalizeWorkspaceList(entries).find((entry) => entry.slug === normalizedWorkspaceSlug) || null;
45
+ }
46
+
47
+ function buildBootstrapApiPath(workspaceSlug = "") {
48
+ const normalizedWorkspaceSlug = normalizeWorkspaceSlug(workspaceSlug);
49
+ if (!normalizedWorkspaceSlug) {
50
+ return "/api/bootstrap";
51
+ }
52
+
53
+ const params = new URLSearchParams({
54
+ workspaceSlug: normalizedWorkspaceSlug
55
+ });
56
+ return `/api/bootstrap?${params.toString()}`;
57
+ }
58
+
59
+ export { buildBootstrapApiPath, findWorkspaceBySlug, normalizeWorkspaceEntry, normalizeWorkspaceList };
@@ -0,0 +1,10 @@
1
+ import { createTransientRetryHttpClient } from "@jskit-ai/http-runtime/client";
2
+
3
+ const workspacesWebHttpClient = createTransientRetryHttpClient({
4
+ credentials: "include",
5
+ csrf: {
6
+ sessionPath: "/api/session"
7
+ }
8
+ });
9
+
10
+ export { workspacesWebHttpClient };
@@ -0,0 +1,27 @@
1
+ import { hasPermission, normalizePermissionList } from "@jskit-ai/kernel/shared/support";
2
+
3
+ function toPermissionSet(values) {
4
+ const normalized = normalizePermissionList(values);
5
+ if (normalized.length < 1) {
6
+ return new Set();
7
+ }
8
+ return new Set(normalized);
9
+ }
10
+
11
+ function arePermissionListsEqual(left, right) {
12
+ const leftSet = toPermissionSet(left);
13
+ const rightSet = toPermissionSet(right);
14
+ if (leftSet.size !== rightSet.size) {
15
+ return false;
16
+ }
17
+
18
+ for (const permission of leftSet) {
19
+ if (!rightSet.has(permission)) {
20
+ return false;
21
+ }
22
+ }
23
+
24
+ return true;
25
+ }
26
+
27
+ export { normalizePermissionList, arePermissionListsEqual, hasPermission };
@@ -0,0 +1,163 @@
1
+ import {
2
+ resolveSurfaceIdFromPlacementPathname
3
+ } from "@jskit-ai/shell-web/client/placement";
4
+ import { resolveWorkspaceShellLinkPath } from "./workspaceLinkResolver.js";
5
+ import { resolveSurfaceSwitchTargetsFromPlacementContext } from "./workspaceSurfaceContext.js";
6
+ import { evaluateSurfaceAccess, hasWorkspaceMembership } from "./surfaceAccessPolicy.js";
7
+ import {
8
+ resolveWorkspaceSurfaceIdFromPlacementPathname,
9
+ extractWorkspaceSlugFromSurfacePathname
10
+ } from "./workspaceSurfacePaths.js";
11
+ import {
12
+ mdiArrowRightCircleOutline,
13
+ mdiHomeVariantOutline,
14
+ mdiShieldCrownOutline,
15
+ mdiViewDashboardOutline
16
+ } from "@mdi/js";
17
+
18
+ const SURFACE_SWITCH_ICON_BY_ID = Object.freeze({
19
+ home: mdiHomeVariantOutline,
20
+ app: mdiViewDashboardOutline,
21
+ admin: mdiShieldCrownOutline
22
+ });
23
+
24
+ function resolveSurfaceSwitchIcon(surfaceId = "", explicitIcon = "") {
25
+ const resolvedExplicitIcon = String(explicitIcon || "").trim();
26
+ if (resolvedExplicitIcon) {
27
+ return resolvedExplicitIcon;
28
+ }
29
+
30
+ const normalizedSurfaceId = String(surfaceId || "").trim().toLowerCase();
31
+ return SURFACE_SWITCH_ICON_BY_ID[normalizedSurfaceId] || mdiArrowRightCircleOutline;
32
+ }
33
+
34
+ function resolveCurrentWorkspaceSlug(contextValue, surfaceId) {
35
+ const context = contextValue && typeof contextValue === "object" ? contextValue : {};
36
+ const workspaceSlugFromContext = String(context?.workspace?.slug || "").trim();
37
+ if (workspaceSlugFromContext) {
38
+ return workspaceSlugFromContext;
39
+ }
40
+
41
+ if (typeof window !== "object" || !window?.location?.pathname) {
42
+ return "";
43
+ }
44
+
45
+ const pathname = String(window.location.pathname || "").trim();
46
+ const currentSurfaceId =
47
+ resolveWorkspaceSurfaceIdFromPlacementPathname(context, pathname) ||
48
+ resolveSurfaceIdFromPlacementPathname(context, pathname) ||
49
+ surfaceId;
50
+ return String(extractWorkspaceSlugFromSurfacePathname(context, currentSurfaceId, pathname) || "").trim();
51
+ }
52
+
53
+ function shouldIncludeSurfaceSwitchTarget(surfaceDefinition = null) {
54
+ if (!surfaceDefinition || typeof surfaceDefinition !== "object") {
55
+ return false;
56
+ }
57
+
58
+ if (surfaceDefinition.enabled === false) {
59
+ return false;
60
+ }
61
+
62
+ if (surfaceDefinition.showInSurfaceSwitchMenu === true) {
63
+ return true;
64
+ }
65
+ if (surfaceDefinition.showInSurfaceSwitchMenu === false) {
66
+ return false;
67
+ }
68
+
69
+ return surfaceDefinition.requiresWorkspace === true || surfaceDefinition.requiresAuth === true;
70
+ }
71
+
72
+ function resolveSurfaceSwitchLinkLabel(surfaceDefinition = null, surfaceId = "") {
73
+ const normalizedSurfaceId = String(surfaceId || "").trim();
74
+ const configuredLabel = String(surfaceDefinition?.label || "").trim();
75
+ const label = configuredLabel || normalizedSurfaceId;
76
+ if (!label) {
77
+ return "Go to surface";
78
+ }
79
+ return `Go to ${label.toLowerCase()}`;
80
+ }
81
+
82
+ function resolveSurfaceSwitchLinks({ context, surface } = {}) {
83
+ const source = context && typeof context === "object" ? context : {};
84
+ const targets = resolveSurfaceSwitchTargetsFromPlacementContext(source, surface);
85
+ const currentSurfaceId = String(targets.currentSurfaceId || "").trim().toLowerCase();
86
+ const resolvedWorkspaceSlug = resolveCurrentWorkspaceSlug(source, currentSurfaceId || surface);
87
+ const workspaceSlug = hasWorkspaceMembership(source, resolvedWorkspaceSlug) ? resolvedWorkspaceSlug : "";
88
+ const enabledSurfaceIds = Array.isArray(targets?.surfaceConfig?.enabledSurfaceIds)
89
+ ? targets.surfaceConfig.enabledSurfaceIds
90
+ : [];
91
+ const links = [];
92
+
93
+ for (const targetSurfaceIdCandidate of enabledSurfaceIds) {
94
+ const targetSurfaceId = String(targetSurfaceIdCandidate || "").trim().toLowerCase();
95
+ if (!targetSurfaceId) {
96
+ continue;
97
+ }
98
+ if (targetSurfaceId === currentSurfaceId) {
99
+ continue;
100
+ }
101
+
102
+ const targetSurface = targets.surfaceConfig.surfacesById[targetSurfaceId] || null;
103
+ if (!shouldIncludeSurfaceSwitchTarget(targetSurface)) {
104
+ continue;
105
+ }
106
+
107
+ const targetWorkspaceSlug = targetSurface?.requiresWorkspace === true ? workspaceSlug : "";
108
+ if (targetSurface?.requiresWorkspace === true && !targetWorkspaceSlug) {
109
+ continue;
110
+ }
111
+
112
+ const accessDecision = evaluateSurfaceAccess({
113
+ context: source,
114
+ surfaceId: targetSurfaceId,
115
+ workspaceSlug: targetWorkspaceSlug
116
+ });
117
+ if (!accessDecision.allowed) {
118
+ continue;
119
+ }
120
+
121
+ links.push({
122
+ id: `surface-switch.${targetSurfaceId}`,
123
+ label: resolveSurfaceSwitchLinkLabel(targetSurface, targetSurfaceId),
124
+ icon: resolveSurfaceSwitchIcon(targetSurfaceId, targetSurface?.icon),
125
+ to: resolveWorkspaceShellLinkPath({
126
+ context: source,
127
+ surface: targetSurfaceId,
128
+ workspaceSlug: targetWorkspaceSlug,
129
+ mode: targetSurface?.requiresWorkspace === true ? "workspace" : "surface",
130
+ relativePath: "/"
131
+ })
132
+ });
133
+ }
134
+
135
+ return links;
136
+ }
137
+
138
+ function resolvePrimarySurfaceSwitchLink({ context, surface } = {}) {
139
+ const links = resolveSurfaceSwitchLinks({
140
+ context,
141
+ surface
142
+ });
143
+ return links[0] || null;
144
+ }
145
+
146
+ function resolveProfileSurfaceMenuLinks({ context, surface } = {}) {
147
+ const source = context && typeof context === "object" ? context : {};
148
+ const authenticated = Boolean(source?.auth?.authenticated);
149
+ if (!authenticated) {
150
+ return [];
151
+ }
152
+ return resolveSurfaceSwitchLinks({
153
+ context: source,
154
+ surface
155
+ });
156
+ }
157
+
158
+ export {
159
+ resolveProfileSurfaceMenuLinks,
160
+ resolvePrimarySurfaceSwitchLink,
161
+ resolveSurfaceSwitchLinks,
162
+ hasWorkspaceMembership
163
+ };
@@ -0,0 +1,350 @@
1
+ import { resolveSurfaceDefinitionFromPlacementContext } from "@jskit-ai/shell-web/client/placement";
2
+ import { normalizeSurfaceId } from "@jskit-ai/kernel/shared/surface/registry";
3
+ import {
4
+ normalizeRecord,
5
+ normalizeWorkspaceBootstrapStatusValue
6
+ } from "../support/runtimeNormalization.js";
7
+ import { hasPermission, normalizePermissionList } from "./permissions.js";
8
+
9
+ const WORKSPACE_BOOTSTRAP_STATUS_NOT_FOUND = "not_found";
10
+ const WORKSPACE_BOOTSTRAP_STATUS_FORBIDDEN = "forbidden";
11
+ const WORKSPACE_ACCESS_BLOCKING_STATUSES = new Set([
12
+ WORKSPACE_BOOTSTRAP_STATUS_NOT_FOUND,
13
+ WORKSPACE_BOOTSTRAP_STATUS_FORBIDDEN
14
+ ]);
15
+
16
+ function normalizeSurfaceAccessPolicyId(value = "") {
17
+ return String(value || "")
18
+ .trim()
19
+ .toLowerCase();
20
+ }
21
+
22
+ function normalizeWorkspaceSlug(value = "") {
23
+ return String(value || "")
24
+ .trim()
25
+ .toLowerCase();
26
+ }
27
+
28
+ function normalizeAccessFlagName(value = "") {
29
+ return String(value || "")
30
+ .trim()
31
+ .toLowerCase()
32
+ .replace(/[^a-z0-9]+/g, "");
33
+ }
34
+
35
+ function normalizeStringList(value) {
36
+ const source = Array.isArray(value) ? value : [value];
37
+ const output = [];
38
+ for (const entry of source) {
39
+ const normalizedEntry = normalizeAccessFlagName(entry);
40
+ if (!normalizedEntry || output.includes(normalizedEntry)) {
41
+ continue;
42
+ }
43
+ output.push(normalizedEntry);
44
+ }
45
+ return output;
46
+ }
47
+
48
+ function normalizeSurfaceAccessFlags(value = null) {
49
+ const source = normalizeRecord(value);
50
+ const flags = {};
51
+
52
+ for (const [candidateKey, candidateValue] of Object.entries(source)) {
53
+ const key = normalizeAccessFlagName(candidateKey);
54
+ if (!key) {
55
+ continue;
56
+ }
57
+ flags[key] = candidateValue === true;
58
+ }
59
+
60
+ return flags;
61
+ }
62
+
63
+ function hasPlacementValue(source, key) {
64
+ if (!source || typeof source !== "object") {
65
+ return false;
66
+ }
67
+ return Object.hasOwn(source, key);
68
+ }
69
+
70
+ function hasKnownWorkspaceMembershipContext(contextValue = null) {
71
+ return hasPlacementValue(contextValue, "workspaces");
72
+ }
73
+
74
+ function hasKnownPermissionsContext(contextValue = null) {
75
+ return hasPlacementValue(contextValue, "permissions");
76
+ }
77
+
78
+ function hasKnownSurfaceAccessContext(contextValue = null) {
79
+ return hasPlacementValue(contextValue, "surfaceAccess");
80
+ }
81
+
82
+ function hasWorkspaceMembership(contextValue = null, workspaceSlug = "") {
83
+ const normalizedWorkspaceSlug = normalizeWorkspaceSlug(workspaceSlug);
84
+ if (!normalizedWorkspaceSlug) {
85
+ return false;
86
+ }
87
+
88
+ const context = normalizeRecord(contextValue);
89
+ if (normalizeWorkspaceSlug(context?.workspace?.slug) === normalizedWorkspaceSlug) {
90
+ return true;
91
+ }
92
+
93
+ const workspaces = Array.isArray(context.workspaces) ? context.workspaces : [];
94
+ for (const workspace of workspaces) {
95
+ if (normalizeWorkspaceSlug(workspace?.slug) === normalizedWorkspaceSlug) {
96
+ return true;
97
+ }
98
+ }
99
+
100
+ return false;
101
+ }
102
+
103
+ function resolveSurfaceAccessPolicies(contextValue = null) {
104
+ const context = normalizeRecord(contextValue);
105
+ const configuredPolicies = normalizeRecord(context.surfaceAccessPolicies);
106
+ const policies = {};
107
+
108
+ for (const [candidatePolicyId, candidatePolicy] of Object.entries(configuredPolicies)) {
109
+ const policyId = normalizeSurfaceAccessPolicyId(candidatePolicyId);
110
+ if (!policyId) {
111
+ continue;
112
+ }
113
+ policies[policyId] = normalizeRecord(candidatePolicy);
114
+ }
115
+
116
+ return policies;
117
+ }
118
+
119
+ function resolveSurfaceAccessPolicy(contextValue = null, surfaceDefinition = null) {
120
+ const definition = normalizeRecord(surfaceDefinition);
121
+ const policyId = normalizeSurfaceAccessPolicyId(definition.accessPolicyId);
122
+ const configuredPolicies = resolveSurfaceAccessPolicies(contextValue);
123
+ const configuredPolicy = policyId ? normalizeRecord(configuredPolicies[policyId]) : {};
124
+
125
+ const requireAuth = Object.hasOwn(configuredPolicy, "requireAuth")
126
+ ? configuredPolicy.requireAuth === true
127
+ : definition.requiresAuth === true;
128
+ const requireWorkspaceMembership = Object.hasOwn(configuredPolicy, "requireWorkspaceMembership")
129
+ ? configuredPolicy.requireWorkspaceMembership === true
130
+ : definition.requiresWorkspace === true;
131
+ const requireAnyPermissions = normalizePermissionList(configuredPolicy.requireAnyPermissions);
132
+ const requireAllPermissions = normalizePermissionList(configuredPolicy.requireAllPermissions);
133
+ const requireFlagsAny = normalizeStringList(configuredPolicy.requireFlagsAny);
134
+ const requireFlagsAll = normalizeStringList(configuredPolicy.requireFlagsAll);
135
+
136
+ return Object.freeze({
137
+ policyId,
138
+ requireAuth,
139
+ requireWorkspaceMembership,
140
+ requireAnyPermissions: Object.freeze([...requireAnyPermissions]),
141
+ requireAllPermissions: Object.freeze([...requireAllPermissions]),
142
+ requireFlagsAny: Object.freeze([...requireFlagsAny]),
143
+ requireFlagsAll: Object.freeze([...requireFlagsAll])
144
+ });
145
+ }
146
+
147
+ function toAccessDecision({ allowed = false, pending = false, reason = "" } = {}) {
148
+ return Object.freeze({
149
+ allowed: allowed === true,
150
+ pending: pending === true,
151
+ reason: String(reason || "").trim()
152
+ });
153
+ }
154
+
155
+ function evaluatePermissionRequirements(policy, permissions = []) {
156
+ if (policy.requireAnyPermissions.length > 0) {
157
+ const hasAnyRequiredPermission = policy.requireAnyPermissions.some((permission) => hasPermission(permissions, permission));
158
+ if (!hasAnyRequiredPermission) {
159
+ return toAccessDecision({
160
+ allowed: false,
161
+ reason: "surface-access-missing-any-permission"
162
+ });
163
+ }
164
+ }
165
+
166
+ if (policy.requireAllPermissions.length > 0) {
167
+ for (const permission of policy.requireAllPermissions) {
168
+ if (hasPermission(permissions, permission)) {
169
+ continue;
170
+ }
171
+ return toAccessDecision({
172
+ allowed: false,
173
+ reason: "surface-access-missing-permission"
174
+ });
175
+ }
176
+ }
177
+
178
+ return toAccessDecision({
179
+ allowed: true
180
+ });
181
+ }
182
+
183
+ function evaluateFlagRequirements(policy, flags = {}) {
184
+ const normalizedFlags = normalizeSurfaceAccessFlags(flags);
185
+ if (policy.requireFlagsAll.length > 0) {
186
+ for (const flagName of policy.requireFlagsAll) {
187
+ if (normalizedFlags[flagName] === true) {
188
+ continue;
189
+ }
190
+ return toAccessDecision({
191
+ allowed: false,
192
+ reason: "surface-access-missing-flag"
193
+ });
194
+ }
195
+ }
196
+
197
+ if (policy.requireFlagsAny.length > 0) {
198
+ const hasAnyRequiredFlag = policy.requireFlagsAny.some((flagName) => normalizedFlags[flagName] === true);
199
+ if (!hasAnyRequiredFlag) {
200
+ return toAccessDecision({
201
+ allowed: false,
202
+ reason: "surface-access-missing-any-flag"
203
+ });
204
+ }
205
+ }
206
+
207
+ return toAccessDecision({
208
+ allowed: true
209
+ });
210
+ }
211
+
212
+ function evaluateSurfaceAccess({
213
+ context = null,
214
+ surfaceId = "",
215
+ workspaceSlug = "",
216
+ allowOnUnknown = false
217
+ } = {}) {
218
+ const source = normalizeRecord(context);
219
+ const normalizedSurfaceId = normalizeSurfaceId(surfaceId);
220
+ if (!normalizedSurfaceId) {
221
+ return toAccessDecision({
222
+ allowed: false,
223
+ reason: "surface-access-invalid-surface"
224
+ });
225
+ }
226
+
227
+ const surfaceDefinition = resolveSurfaceDefinitionFromPlacementContext(source, normalizedSurfaceId);
228
+ if (!surfaceDefinition || surfaceDefinition.enabled === false) {
229
+ return toAccessDecision({
230
+ allowed: false,
231
+ reason: "surface-access-disabled"
232
+ });
233
+ }
234
+
235
+ const policy = resolveSurfaceAccessPolicy(source, surfaceDefinition);
236
+ if (policy.requireAuth && source?.auth?.authenticated !== true) {
237
+ return toAccessDecision({
238
+ allowed: false,
239
+ reason: "surface-access-auth-required"
240
+ });
241
+ }
242
+
243
+ const normalizedWorkspaceSlug = normalizeWorkspaceSlug(workspaceSlug);
244
+ if (policy.requireWorkspaceMembership) {
245
+ if (!normalizedWorkspaceSlug) {
246
+ return toAccessDecision({
247
+ allowed: false,
248
+ reason: "surface-access-workspace-required"
249
+ });
250
+ }
251
+
252
+ const workspaceBootstrapStatuses = normalizeRecord(source.workspaceBootstrapStatuses);
253
+ const workspaceStatus = normalizeWorkspaceBootstrapStatusValue(
254
+ workspaceBootstrapStatuses[normalizedWorkspaceSlug],
255
+ WORKSPACE_ACCESS_BLOCKING_STATUSES
256
+ );
257
+ if (workspaceStatus === WORKSPACE_BOOTSTRAP_STATUS_NOT_FOUND) {
258
+ return toAccessDecision({
259
+ allowed: false,
260
+ reason: "surface-access-workspace-not-found"
261
+ });
262
+ }
263
+ if (workspaceStatus === WORKSPACE_BOOTSTRAP_STATUS_FORBIDDEN) {
264
+ return toAccessDecision({
265
+ allowed: false,
266
+ reason: "surface-access-workspace-forbidden"
267
+ });
268
+ }
269
+
270
+ if (hasKnownWorkspaceMembershipContext(source)) {
271
+ if (!hasWorkspaceMembership(source, normalizedWorkspaceSlug)) {
272
+ if (allowOnUnknown && !workspaceStatus) {
273
+ return toAccessDecision({
274
+ allowed: true,
275
+ pending: true
276
+ });
277
+ }
278
+ return toAccessDecision({
279
+ allowed: false,
280
+ reason: "surface-access-workspace-membership-required"
281
+ });
282
+ }
283
+ } else if (allowOnUnknown) {
284
+ return toAccessDecision({
285
+ allowed: true,
286
+ pending: true
287
+ });
288
+ } else {
289
+ return toAccessDecision({
290
+ allowed: false,
291
+ pending: true,
292
+ reason: "surface-access-pending"
293
+ });
294
+ }
295
+ }
296
+
297
+ const placementPermissions = normalizePermissionList(source.permissions);
298
+ if (policy.requireAnyPermissions.length > 0 || policy.requireAllPermissions.length > 0) {
299
+ if (!hasKnownPermissionsContext(source)) {
300
+ if (allowOnUnknown) {
301
+ return toAccessDecision({
302
+ allowed: true,
303
+ pending: true
304
+ });
305
+ }
306
+ return toAccessDecision({
307
+ allowed: false,
308
+ pending: true,
309
+ reason: "surface-access-pending"
310
+ });
311
+ }
312
+
313
+ const permissionDecision = evaluatePermissionRequirements(policy, placementPermissions);
314
+ if (!permissionDecision.allowed) {
315
+ return permissionDecision;
316
+ }
317
+ }
318
+
319
+ if (policy.requireFlagsAny.length > 0 || policy.requireFlagsAll.length > 0) {
320
+ if (!hasKnownSurfaceAccessContext(source)) {
321
+ if (allowOnUnknown) {
322
+ return toAccessDecision({
323
+ allowed: true,
324
+ pending: true
325
+ });
326
+ }
327
+ return toAccessDecision({
328
+ allowed: false,
329
+ pending: true,
330
+ reason: "surface-access-pending"
331
+ });
332
+ }
333
+
334
+ const accessFlags = normalizeRecord(source.surfaceAccess);
335
+ const flagDecision = evaluateFlagRequirements(policy, accessFlags);
336
+ if (!flagDecision.allowed) {
337
+ return flagDecision;
338
+ }
339
+ }
340
+
341
+ return toAccessDecision({
342
+ allowed: true
343
+ });
344
+ }
345
+
346
+ export {
347
+ hasWorkspaceMembership,
348
+ resolveSurfaceAccessPolicy,
349
+ evaluateSurfaceAccess
350
+ };