@jskit-ai/users-web 0.1.52 → 0.1.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.descriptor.mjs +14 -96
- package/package.json +16 -11
- package/src/client/account-settings/sections.js +74 -0
- package/src/client/composables/account-settings/accountSettingsRuntimeHelpers.js +2 -38
- package/src/client/composables/crud/crudLookupFieldRuntime.js +2 -2
- package/src/client/composables/internal/crudListParentTitleSupport.js +1 -1
- package/src/client/composables/internal/useOperationScope.js +12 -12
- package/src/client/composables/records/useAddEdit.js +2 -2
- package/src/client/composables/records/useList.js +3 -3
- package/src/client/composables/records/useView.js +2 -2
- package/src/client/composables/support/scopeHelpers.js +19 -19
- package/src/client/composables/useAccess.js +3 -3
- package/src/client/composables/useAccountSettingsRuntime.js +8 -156
- package/src/client/composables/useCommand.js +2 -2
- package/src/client/composables/useCrudListParentTitle.js +2 -2
- package/src/client/composables/usePaths.js +50 -38
- package/src/client/composables/useScopeRuntime.js +55 -27
- package/src/client/composables/useSurfaceRouteContext.js +1 -7
- package/src/client/index.js +0 -1
- package/src/client/lib/bootstrap.js +0 -63
- package/src/client/lib/httpClient.js +2 -59
- package/src/client/lib/theme.js +12 -189
- package/src/client/providers/UsersWebClientProvider.js +2 -25
- package/src/client/providers/bootUsersWebClientProvider.js +28 -0
- package/src/shared/toolsOutletContracts.js +1 -8
- package/templates/src/components/account/settings/AccountSettingsClientElement.vue +33 -21
- package/test/accountSettingsSections.test.js +79 -0
- package/test/exportsContract.test.js +2 -2
- package/test/scopeHelpers.test.js +6 -6
- package/test/settingsPlacementContract.test.js +4 -49
- package/test/theme.test.js +0 -56
- package/src/client/components/ConsoleSettingsClientElement.vue +0 -24
- package/src/client/components/MembersAdminClientElement.vue +0 -400
- package/src/client/components/UsersProfileSurfaceSwitchMenuItem.vue +0 -39
- package/src/client/components/UsersWorkspaceMembersMenuItem.vue +0 -36
- package/src/client/components/UsersWorkspacePermissionMenuItem.vue +0 -90
- package/src/client/components/UsersWorkspaceSelector.vue +0 -248
- package/src/client/components/UsersWorkspaceSettingsMenuItem.vue +0 -39
- package/src/client/components/UsersWorkspaceToolsWidget.vue +0 -12
- package/src/client/components/WorkspaceMembersClientElement.vue +0 -655
- package/src/client/components/WorkspaceProfileClientElement.vue +0 -116
- package/src/client/components/WorkspaceSettingsClientElement.vue +0 -102
- package/src/client/components/WorkspaceSettingsFieldsClientElement.vue +0 -265
- package/src/client/components/WorkspacesClientElement.vue +0 -509
- package/src/client/composables/account-settings/accountSettingsInvitesRuntime.js +0 -88
- package/src/client/composables/useBootstrapQuery.js +0 -52
- package/src/client/composables/useWorkspaceRouteContext.js +0 -28
- package/src/client/composables/useWorkspaceSurfaceId.js +0 -43
- package/src/client/lib/menuIcons.js +0 -210
- package/src/client/lib/profileSurfaceMenuLinks.js +0 -142
- package/src/client/lib/surfaceAccessPolicy.js +0 -350
- package/src/client/lib/workspaceLinkResolver.js +0 -207
- package/src/client/lib/workspaceSurfaceContext.js +0 -82
- package/src/client/lib/workspaceSurfacePaths.js +0 -163
- package/src/client/providers/UsersWorkspacesClientProvider.js +0 -24
- package/src/client/runtime/bootstrapPlacementRouteGuards.js +0 -371
- package/src/client/runtime/bootstrapPlacementRuntime.js +0 -463
- package/src/client/runtime/bootstrapPlacementRuntimeConstants.js +0 -28
- package/src/client/runtime/bootstrapPlacementRuntimeHelpers.js +0 -147
- package/src/client/support/menuLinkTarget.js +0 -93
- package/src/client/support/realtimeWorkspace.js +0 -21
- package/src/client/support/runtimeNormalization.js +0 -27
- package/src/client/support/workspaceQueryKeys.js +0 -15
- package/templates/src/components/account/settings/AccountSettingsInvitesSection.vue +0 -77
- package/templates/src/pages/console/settings/index.vue +0 -8
- package/templates/src/pages/console/settings.vue +0 -32
- package/test/bootstrapPlacementRuntime.test.js +0 -1095
- package/test/menuIcons.test.js +0 -35
- package/test/menuLinkTarget.test.js +0 -116
- package/test/profileSurfaceMenuLinks.test.js +0 -207
- package/test/surfaceAccessPolicy.test.js +0 -129
- package/test/workspaceLinkResolver.test.js +0 -61
- package/test/workspaceSurfacePaths.test.js +0 -39
|
@@ -1,350 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
import { unref } from "vue";
|
|
2
|
-
import { resolveLinkPath } from "@jskit-ai/kernel/shared";
|
|
3
|
-
import { normalizeSurfaceId } from "@jskit-ai/kernel/shared/surface/registry";
|
|
4
|
-
import {
|
|
5
|
-
useWebPlacementContext,
|
|
6
|
-
resolveRuntimePathname,
|
|
7
|
-
resolveSurfaceDefinitionFromPlacementContext,
|
|
8
|
-
resolveSurfaceIdFromPlacementPathname,
|
|
9
|
-
resolveSurfaceRootPathFromPlacementContext
|
|
10
|
-
} from "@jskit-ai/shell-web/client/placement";
|
|
11
|
-
import {
|
|
12
|
-
resolveWorkspaceSurfaceIdFromPlacementPathname,
|
|
13
|
-
resolveSurfaceWorkspacePathFromPlacementContext,
|
|
14
|
-
extractWorkspaceSlugFromSurfacePathname
|
|
15
|
-
} from "./workspaceSurfacePaths.js";
|
|
16
|
-
import { surfaceRequiresWorkspaceFromPlacementContext } from "./workspaceSurfaceContext.js";
|
|
17
|
-
import { parseWorkspacePathname } from "@jskit-ai/users-core/shared/support/workspacePathModel";
|
|
18
|
-
|
|
19
|
-
function resolveSurfaceBasePath(context = null, surface = "") {
|
|
20
|
-
const normalizedSurface = normalizeSurfaceId(surface);
|
|
21
|
-
if (!normalizedSurface) {
|
|
22
|
-
return "";
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
if (!resolveSurfaceDefinitionFromPlacementContext(context, normalizedSurface)) {
|
|
26
|
-
return "";
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return resolveSurfaceRootPathFromPlacementContext(context, normalizedSurface);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
function resolveWorkspaceSlugFromContextOrPath({
|
|
33
|
-
context = null,
|
|
34
|
-
surface = "",
|
|
35
|
-
workspaceSlug = "",
|
|
36
|
-
pathname = ""
|
|
37
|
-
} = {}) {
|
|
38
|
-
const explicitWorkspaceSlug = String(workspaceSlug || "").trim();
|
|
39
|
-
if (explicitWorkspaceSlug) {
|
|
40
|
-
return explicitWorkspaceSlug;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const workspaceSlugFromContext = String(context?.workspace?.slug || "").trim();
|
|
44
|
-
if (workspaceSlugFromContext) {
|
|
45
|
-
return workspaceSlugFromContext;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const currentPathname = resolveRuntimePathname(pathname);
|
|
49
|
-
const workspaceSlugFromPath = String(parseWorkspacePathname(currentPathname)?.workspaceSlug || "").trim();
|
|
50
|
-
if (workspaceSlugFromPath) {
|
|
51
|
-
return workspaceSlugFromPath;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const normalizedSurface = normalizeSurfaceId(surface);
|
|
55
|
-
const workspaceSurfaceId = resolveWorkspaceSurfaceIdFromPlacementPathname(context, currentPathname);
|
|
56
|
-
const surfaceIdFromPath = workspaceSurfaceId || resolveSurfaceIdFromPlacementPathname(context, currentPathname);
|
|
57
|
-
const activeSurfaceId = normalizeSurfaceId(surfaceIdFromPath || normalizedSurface);
|
|
58
|
-
if (!activeSurfaceId) {
|
|
59
|
-
return "";
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
return String(extractWorkspaceSlugFromSurfacePathname(context, activeSurfaceId, currentPathname) || "").trim();
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function resolveWorkspaceBasePath(context = null, surface = "", workspaceSlug = "") {
|
|
66
|
-
const normalizedSurface = normalizeSurfaceId(surface);
|
|
67
|
-
const normalizedWorkspaceSlug = String(workspaceSlug || "").trim();
|
|
68
|
-
if (!normalizedSurface || !normalizedWorkspaceSlug) {
|
|
69
|
-
return "";
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (!resolveSurfaceDefinitionFromPlacementContext(context, normalizedSurface)) {
|
|
73
|
-
return "";
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (!surfaceRequiresWorkspaceFromPlacementContext(context, normalizedSurface)) {
|
|
77
|
-
return resolveSurfaceBasePath(context, normalizedSurface);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return resolveSurfaceWorkspacePathFromPlacementContext(context, normalizedSurface, normalizedWorkspaceSlug, "/");
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function resolveWorkspaceShellLinkPath({
|
|
84
|
-
context = null,
|
|
85
|
-
surface = "",
|
|
86
|
-
mode = "auto",
|
|
87
|
-
explicitTo = "",
|
|
88
|
-
relativePath = "/",
|
|
89
|
-
workspaceRelativePath = "",
|
|
90
|
-
surfaceRelativePath = "",
|
|
91
|
-
workspaceSlug = "",
|
|
92
|
-
pathname = ""
|
|
93
|
-
} = {}) {
|
|
94
|
-
const explicitTarget = String(explicitTo || "").trim();
|
|
95
|
-
if (explicitTarget) {
|
|
96
|
-
return explicitTarget;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const normalizedSurface = normalizeSurfaceId(surface);
|
|
100
|
-
const normalizedMode = String(mode || "auto").trim().toLowerCase();
|
|
101
|
-
const hasSurfaceDefinition = Boolean(
|
|
102
|
-
normalizedSurface && resolveSurfaceDefinitionFromPlacementContext(context, normalizedSurface)
|
|
103
|
-
);
|
|
104
|
-
if (!hasSurfaceDefinition) {
|
|
105
|
-
return "";
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const resolvedWorkspaceSlug = resolveWorkspaceSlugFromContextOrPath({
|
|
109
|
-
context,
|
|
110
|
-
surface: normalizedSurface,
|
|
111
|
-
workspaceSlug,
|
|
112
|
-
pathname
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
const nextWorkspaceRelativePath = String(workspaceRelativePath || "").trim() || String(relativePath || "").trim() || "/";
|
|
116
|
-
const nextSurfaceRelativePath = String(surfaceRelativePath || "").trim() || String(relativePath || "").trim() || "/";
|
|
117
|
-
const nextSurfaceBasePath = resolveSurfaceBasePath(context, normalizedSurface);
|
|
118
|
-
|
|
119
|
-
if (normalizedMode === "surface") {
|
|
120
|
-
return resolveLinkPath(nextSurfaceBasePath, nextSurfaceRelativePath);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
if (normalizedMode === "workspace") {
|
|
124
|
-
if (!surfaceRequiresWorkspaceFromPlacementContext(context, normalizedSurface)) {
|
|
125
|
-
return resolveLinkPath(nextSurfaceBasePath, nextSurfaceRelativePath);
|
|
126
|
-
}
|
|
127
|
-
if (!resolvedWorkspaceSlug) {
|
|
128
|
-
return "";
|
|
129
|
-
}
|
|
130
|
-
const workspaceBasePath = resolveWorkspaceBasePath(context, normalizedSurface, resolvedWorkspaceSlug);
|
|
131
|
-
if (!workspaceBasePath) {
|
|
132
|
-
return "";
|
|
133
|
-
}
|
|
134
|
-
return resolveLinkPath(
|
|
135
|
-
workspaceBasePath,
|
|
136
|
-
nextWorkspaceRelativePath
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (surfaceRequiresWorkspaceFromPlacementContext(context, normalizedSurface)) {
|
|
141
|
-
if (!resolvedWorkspaceSlug) {
|
|
142
|
-
return "";
|
|
143
|
-
}
|
|
144
|
-
const workspaceBasePath = resolveWorkspaceBasePath(context, normalizedSurface, resolvedWorkspaceSlug);
|
|
145
|
-
if (!workspaceBasePath) {
|
|
146
|
-
return "";
|
|
147
|
-
}
|
|
148
|
-
return resolveLinkPath(
|
|
149
|
-
workspaceBasePath,
|
|
150
|
-
nextWorkspaceRelativePath
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return resolveLinkPath(nextSurfaceBasePath, nextSurfaceRelativePath);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function useWorkspaceLinkResolver({ surface = "", workspaceSlug = "", pathname = "" } = {}) {
|
|
158
|
-
const { context: placementContext } = useWebPlacementContext();
|
|
159
|
-
|
|
160
|
-
function resolve(relativePath = "/", options = {}) {
|
|
161
|
-
return resolveWorkspaceShellLinkPath({
|
|
162
|
-
context: placementContext.value,
|
|
163
|
-
surface: String(unref(options.surface ?? surface) || ""),
|
|
164
|
-
workspaceSlug: String(unref(options.workspaceSlug ?? workspaceSlug) || ""),
|
|
165
|
-
pathname: String(unref(options.pathname ?? pathname) || ""),
|
|
166
|
-
mode: String(options.mode || "auto"),
|
|
167
|
-
explicitTo: options.explicitTo,
|
|
168
|
-
relativePath,
|
|
169
|
-
workspaceRelativePath: options.workspaceRelativePath,
|
|
170
|
-
surfaceRelativePath: options.surfaceRelativePath
|
|
171
|
-
});
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
function toSurface(relativePath = "/", options = {}) {
|
|
175
|
-
return resolve(relativePath, {
|
|
176
|
-
...options,
|
|
177
|
-
mode: "surface"
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function toWorkspace(relativePath = "/", options = {}) {
|
|
182
|
-
return resolve(relativePath, {
|
|
183
|
-
...options,
|
|
184
|
-
mode: "workspace"
|
|
185
|
-
});
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function toAuto(relativePath = "/", options = {}) {
|
|
189
|
-
return resolve(relativePath, {
|
|
190
|
-
...options,
|
|
191
|
-
mode: "auto"
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
return Object.freeze({
|
|
196
|
-
resolve,
|
|
197
|
-
toSurface,
|
|
198
|
-
toWorkspace,
|
|
199
|
-
toAuto
|
|
200
|
-
});
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export {
|
|
204
|
-
resolveWorkspaceSlugFromContextOrPath,
|
|
205
|
-
resolveWorkspaceShellLinkPath,
|
|
206
|
-
useWorkspaceLinkResolver
|
|
207
|
-
};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { normalizeSurfaceId } from "@jskit-ai/kernel/shared/surface";
|
|
2
|
-
import {
|
|
3
|
-
readPlacementSurfaceConfig,
|
|
4
|
-
resolveSurfaceDefinitionFromPlacementContext
|
|
5
|
-
} from "@jskit-ai/shell-web/client/placement";
|
|
6
|
-
|
|
7
|
-
function listWorkspaceSurfaceIdsFromSurfaceConfig(surfaceConfig = null) {
|
|
8
|
-
return listSurfaceIdsFromSurfaceConfig(surfaceConfig, {
|
|
9
|
-
requiresWorkspace: true
|
|
10
|
-
});
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
function listNonWorkspaceSurfaceIdsFromSurfaceConfig(surfaceConfig = null) {
|
|
14
|
-
return listSurfaceIdsFromSurfaceConfig(surfaceConfig, {
|
|
15
|
-
requiresWorkspace: false
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function listSurfaceIdsFromSurfaceConfig(surfaceConfig = null, { requiresWorkspace = null } = {}) {
|
|
20
|
-
const source = surfaceConfig && typeof surfaceConfig === "object" ? surfaceConfig : {};
|
|
21
|
-
const enabledSurfaceIds = Array.isArray(source.enabledSurfaceIds) ? source.enabledSurfaceIds : [];
|
|
22
|
-
const surfacesById = source.surfacesById && typeof source.surfacesById === "object" ? source.surfacesById : {};
|
|
23
|
-
|
|
24
|
-
const result = [];
|
|
25
|
-
for (const candidate of enabledSurfaceIds) {
|
|
26
|
-
const surfaceId = normalizeSurfaceId(candidate);
|
|
27
|
-
if (!surfaceId) {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
const surfaceRequiresWorkspace = surfacesById[surfaceId]?.requiresWorkspace === true;
|
|
31
|
-
if (requiresWorkspace === true && !surfaceRequiresWorkspace) {
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (requiresWorkspace === false && surfaceRequiresWorkspace) {
|
|
35
|
-
continue;
|
|
36
|
-
}
|
|
37
|
-
result.push(surfaceId);
|
|
38
|
-
}
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function surfaceRequiresWorkspaceFromPlacementContext(contextValue = null, surfaceId = "") {
|
|
43
|
-
return Boolean(resolveSurfaceDefinitionFromPlacementContext(contextValue, surfaceId)?.requiresWorkspace);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function firstAlternativeSurfaceId(surfaceIds = [], excludeSurfaceId = "") {
|
|
47
|
-
const normalizedExcludeSurfaceId = normalizeSurfaceId(excludeSurfaceId);
|
|
48
|
-
for (const candidate of Array.isArray(surfaceIds) ? surfaceIds : []) {
|
|
49
|
-
const surfaceId = normalizeSurfaceId(candidate);
|
|
50
|
-
if (!surfaceId || surfaceId === normalizedExcludeSurfaceId) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
return surfaceId;
|
|
54
|
-
}
|
|
55
|
-
return "";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function resolveSurfaceSwitchTargetsFromPlacementContext(contextValue = null, surfaceId = "") {
|
|
59
|
-
const surfaceConfig = readPlacementSurfaceConfig(contextValue);
|
|
60
|
-
const currentSurface = resolveSurfaceDefinitionFromPlacementContext(contextValue, surfaceId);
|
|
61
|
-
const currentSurfaceId = normalizeSurfaceId(currentSurface?.id);
|
|
62
|
-
const defaultSurfaceId = normalizeSurfaceId(surfaceConfig.defaultSurfaceId);
|
|
63
|
-
const defaultSurface = defaultSurfaceId ? surfaceConfig.surfacesById[defaultSurfaceId] || null : null;
|
|
64
|
-
const workspaceSurfaceIds = listWorkspaceSurfaceIdsFromSurfaceConfig(surfaceConfig);
|
|
65
|
-
const nonWorkspaceSurfaceIds = listNonWorkspaceSurfaceIdsFromSurfaceConfig(surfaceConfig);
|
|
66
|
-
|
|
67
|
-
return Object.freeze({
|
|
68
|
-
surfaceConfig,
|
|
69
|
-
currentSurfaceId,
|
|
70
|
-
currentSurface,
|
|
71
|
-
defaultSurfaceId,
|
|
72
|
-
defaultSurface,
|
|
73
|
-
workspaceSurfaceId: firstAlternativeSurfaceId(workspaceSurfaceIds, currentSurfaceId),
|
|
74
|
-
nonWorkspaceSurfaceId: firstAlternativeSurfaceId(nonWorkspaceSurfaceIds, currentSurfaceId)
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
export {
|
|
79
|
-
listWorkspaceSurfaceIdsFromSurfaceConfig,
|
|
80
|
-
surfaceRequiresWorkspaceFromPlacementContext,
|
|
81
|
-
resolveSurfaceSwitchTargetsFromPlacementContext
|
|
82
|
-
};
|