@jskit-ai/workspaces-web 0.2.8 → 0.2.10

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
@@ -12,6 +12,7 @@ import { findWorkspaceBySlug, normalizeWorkspaceEntry, normalizeWorkspaceList }
12
12
  import { usePaths } from "@jskit-ai/shell-web/client/navigation/usePaths";
13
13
  import { resolveSurfaceSwitchTargetsFromPlacementContext, surfaceRequiresWorkspaceFromPlacementContext } from "../lib/workspaceSurfaceContext.js";
14
14
  import { resolveWorkspaceSurfaceIdFromPlacementPathname, extractWorkspaceSlugFromSurfacePathname } from "../lib/workspaceSurfacePaths.js";
15
+ import { assignPageLocation, pagePathname } from "../browser.js";
15
16
  import { useJskitText } from "../i18n.js";
16
17
 
17
18
  const props = defineProps({
@@ -37,21 +38,7 @@ const router = useRouter();
37
38
  const { context: placementContext } = useWebPlacementContext();
38
39
  const paths = usePaths();
39
40
 
40
- function resolveBrowserPath() {
41
- if (typeof window !== "object" || !window || !window.location) {
42
- return "/";
43
- }
44
- const pathname = String(window.location.pathname || "").trim();
45
- return pathname || "/";
46
- }
47
-
48
- const currentPath = computed(() => {
49
- const routePath = String(route?.path || "").trim();
50
- if (routePath) {
51
- return routePath;
52
- }
53
- return resolveBrowserPath();
54
- });
41
+ const currentPath = computed(() => String(route.path || "").trim() || pagePathname() || "/");
55
42
 
56
43
  const currentSurfaceId = computed(() => {
57
44
  return (
@@ -137,10 +124,9 @@ async function navigateToWorkspace(slug) {
137
124
 
138
125
  try {
139
126
  if (currentPath.value !== targetPath || !navigationTarget.sameOrigin) {
140
- if (navigationTarget.sameOrigin && router && typeof router.push === "function") {
127
+ if (navigationTarget.sameOrigin) {
141
128
  await router.push(navigationTarget.href);
142
- } else if (typeof window === "object" && window && window.location) {
143
- window.location.assign(navigationTarget.href);
129
+ } else if (assignPageLocation(navigationTarget.href)) {
144
130
  return;
145
131
  } else {
146
132
  throw new Error(t("jskit.workspaces.selector.routerUnavailable"));
@@ -1,232 +1,33 @@
1
1
  <script setup>
2
- import { computed, reactive, ref, watch } from "vue";
3
- import { useRoute, useRouter } from "vue-router";
4
- import {
5
- useWebPlacementContext,
6
- resolveSurfaceNavigationTargetFromPlacementContext
7
- } from "@jskit-ai/shell-web/client/placement";
8
- import { useShellWebErrorRuntime } from "@jskit-ai/shell-web/client/error";
9
- import { normalizeWorkspaceList } from "../lib/bootstrap.js";
10
- import { readLastWorkspaceSlug, resolveWorkspaceLandingSlug } from "../lib/lastWorkspace.js";
11
- import { ROUTE_VISIBILITY_PUBLIC } from "@jskit-ai/kernel/shared/support/visibility";
12
- import {
13
- WORKSPACES_TRANSPORT,
14
- WORKSPACE_INVITE_REDEEM_TRANSPORT
15
- } from "@jskit-ai/workspaces-core/shared/jsonApiTransports";
16
- import { useCommand } from "@jskit-ai/http-web/client/composables/useCommand";
17
- import { useView } from "@jskit-ai/http-web/client/composables/useView";
18
- import { usePaths } from "@jskit-ai/shell-web/client/navigation/usePaths";
19
- import { useRealtimeQueryInvalidation } from "@jskit-ai/http-web/client/composables/useRealtimeQueryInvalidation";
20
- import { useWorkspaceSurfaceId } from "../composables/useWorkspaceSurfaceId.js";
21
- import { normalizeRecordId } from "@jskit-ai/kernel/shared/support/normalize";
2
+ import { useWorkspacesLanding } from "../composables/useWorkspacesLanding.js";
22
3
  import { useJskitText } from "../i18n.js";
23
4
 
24
- function normalizePendingInvite(entry) {
25
- if (!entry || typeof entry !== "object") {
26
- return null;
27
- }
28
-
29
- const id = normalizeRecordId(entry.id, { fallback: null });
30
- const workspaceId = normalizeRecordId(entry.workspaceId, { fallback: null });
31
- if (!id || !workspaceId) {
32
- return null;
33
- }
34
-
35
- const workspaceSlug = String(entry.workspaceSlug || "").trim();
36
- const token = String(entry.token || "").trim();
37
- if (!workspaceSlug || !token) {
38
- return null;
39
- }
40
-
41
- return {
42
- id,
43
- token,
44
- workspaceId,
45
- workspaceSlug,
46
- workspaceName: String(entry.workspaceName || workspaceSlug).trim() || workspaceSlug,
47
- workspaceAvatarUrl: String(entry.workspaceAvatarUrl || "").trim(),
48
- roleSid: String(entry.roleSid || "member").trim().toLowerCase() || "member",
49
- roleLabel: typeof entry.roleLabel === "string" ? entry.roleLabel.trim() : "",
50
- status: String(entry.status || "pending").trim().toLowerCase() || "pending",
51
- expiresAt: String(entry.expiresAt || "").trim()
52
- };
53
- }
54
-
55
- const { t, errorMessage } = useJskitText();
56
- const route = useRoute();
57
- const router = useRouter();
58
- const { context: placementContext } = useWebPlacementContext();
59
- const paths = usePaths();
60
- const errorRuntime = useShellWebErrorRuntime();
61
-
62
- const selectingWorkspaceSlug = ref("");
63
- const bootstrapModel = reactive({
64
- sessionAuthenticated: false,
65
- userId: "",
66
- tenancyMode: "none",
67
- workspaceAllowSelfCreate: false,
68
- workspaceInvitesEnabled: false,
69
- workspaces: [],
70
- pendingInvites: []
71
- });
72
- const inviteAction = ref({
73
- token: "",
74
- decision: ""
75
- });
76
- const createWorkspaceModel = reactive({
77
- name: "",
78
- slug: ""
79
- });
80
- const redeemInviteModel = reactive({
81
- token: "",
82
- decision: ""
83
- });
84
- const bootstrapQueryKey = Object.freeze(["workspaces-web", "bootstrap", "__none__"]);
85
- const OWNERSHIP_PUBLIC = ROUTE_VISIBILITY_PUBLIC;
86
-
87
- const bootstrapView = useView({
88
- ownershipFilter: OWNERSHIP_PUBLIC,
89
- apiSuffix: "/bootstrap",
90
- queryKeyFactory: () => bootstrapQueryKey,
91
- realtime: {
92
- event: "workspace.settings.changed"
93
- },
94
- fallbackLoadError: t("jskit.workspaces.workspacesView.loadFailed"),
95
- model: bootstrapModel,
96
- mapLoadedToModel: (model, payload = {}) => {
97
- model.sessionAuthenticated = Boolean(payload?.session?.authenticated);
98
- model.userId = String(payload?.session?.userId || "");
99
- model.tenancyMode = String(payload?.tenancy?.mode || "").trim().toLowerCase() || "none";
100
- model.workspaceAllowSelfCreate = payload?.tenancy?.workspace?.allowSelfCreate === true;
101
- model.workspaceInvitesEnabled = payload?.app?.features?.workspaceInvites === true;
102
- model.workspaces = normalizeWorkspaceList(payload?.workspaces);
103
- model.pendingInvites = model.workspaceInvitesEnabled
104
- ? (Array.isArray(payload?.pendingInvites) ? payload.pendingInvites : [])
105
- .map(normalizePendingInvite)
106
- .filter(Boolean)
107
- : [];
108
- }
109
- });
110
-
111
- const redeemInviteCommand = useCommand({
112
- ownershipFilter: OWNERSHIP_PUBLIC,
113
- apiSuffix: "/workspace/invitations/redeem",
114
- writeMethod: "POST",
115
- transport: WORKSPACE_INVITE_REDEEM_TRANSPORT,
116
- fallbackRunError: t("jskit.workspaces.common.respondToInvitationFailed"),
117
- suppressSuccessMessage: true,
118
- model: redeemInviteModel,
119
- buildRawPayload: (model) => ({
120
- token: String(model.token || "").trim(),
121
- decision: String(model.decision || "").trim().toLowerCase()
122
- }),
123
- messages: {
124
- error: t("jskit.workspaces.common.respondToInvitationFailed")
125
- }
126
- });
127
-
128
- const createWorkspaceCommand = useCommand({
129
- ownershipFilter: OWNERSHIP_PUBLIC,
130
- apiSuffix: "/workspaces",
131
- writeMethod: "POST",
132
- transport: WORKSPACES_TRANSPORT,
133
- fallbackRunError: t("jskit.workspaces.workspacesView.createFailed"),
134
- suppressSuccessMessage: true,
135
- model: createWorkspaceModel,
136
- buildRawPayload: (model) => {
137
- const payload = {
138
- name: String(model.name || "").trim()
139
- };
140
- const slug = String(model.slug || "").trim().toLowerCase();
141
- if (slug) {
142
- payload.slug = slug;
143
- }
144
- return payload;
145
- },
146
- messages: {
147
- error: t("jskit.workspaces.workspacesView.createFailed")
148
- }
149
- });
150
-
151
- useRealtimeQueryInvalidation({
152
- event: "workspaces.changed",
153
- queryKey: bootstrapQueryKey
154
- });
155
-
156
- useRealtimeQueryInvalidation({
157
- event: "workspace.invitations.pending.changed",
158
- queryKey: bootstrapQueryKey
159
- });
160
-
161
- const workspaceItems = computed(() => {
162
- return Array.isArray(bootstrapModel.workspaces) ? bootstrapModel.workspaces : [];
163
- });
164
-
165
- const pendingInvites = computed(() => {
166
- return Array.isArray(bootstrapModel.pendingInvites) ? bootstrapModel.pendingInvites : [];
167
- });
168
- const workspaceInvitesEnabled = computed(() => bootstrapModel.workspaceInvitesEnabled === true);
169
-
170
- const isBootstrapping = computed(() => Boolean(bootstrapView.isLoading));
171
- const isRefreshingBootstrap = computed(() => Boolean(bootstrapView.isRefetching));
172
- const bootstrapLoadError = computed(() => String(bootstrapView.loadError || "").trim());
173
- const canCreateWorkspace = computed(() => bootstrapModel.workspaceAllowSelfCreate === true);
174
- const isCreatingWorkspace = computed(() => Boolean(createWorkspaceCommand.isRunning));
175
-
176
- function reportFeedback({
177
- message,
178
- severity = "error",
179
- channel = "",
180
- dedupeKey = ""
181
- } = {}) {
182
- const normalizedMessage = String(message || "").trim();
183
- if (!normalizedMessage) {
184
- return;
185
- }
186
-
187
- errorRuntime.report({
188
- source: "workspaces-web.workspaces-view",
189
- message: normalizedMessage,
190
- intent: "action-feedback",
191
- severity,
192
- channel,
193
- dedupeKey: dedupeKey || `workspaces-web.workspaces-view:${severity}:${normalizedMessage}`,
194
- dedupeWindowMs: 3000
195
- });
196
- }
197
-
198
- const { workspaceSurfaceId } = useWorkspaceSurfaceId({
199
- route,
200
- placementContext
201
- });
5
+ const { t } = useJskitText();
6
+
7
+ const {
8
+ selectingWorkspaceSlug,
9
+ inviteAction,
10
+ createWorkspaceModel,
11
+ workspaceItems,
12
+ pendingInvites,
13
+ workspaceInvitesEnabled,
14
+ isBootstrapping,
15
+ isRefreshingBootstrap,
16
+ bootstrapLoadError,
17
+ canCreateWorkspace,
18
+ isCreatingWorkspace,
19
+ openWorkspace,
20
+ acceptInvite,
21
+ refuseInvite,
22
+ createWorkspace,
23
+ refreshBootstrap
24
+ } = useWorkspacesLanding();
202
25
 
203
26
  function workspaceInitials(workspace) {
204
27
  const source = String(workspace?.name || workspace?.slug || "W").trim();
205
28
  return source.slice(0, 2).toUpperCase();
206
29
  }
207
30
 
208
- function workspaceHomePath(workspaceSlug) {
209
- const normalizedSlug = String(workspaceSlug || "").trim();
210
- if (!normalizedSlug || !workspaceSurfaceId.value) {
211
- return "";
212
- }
213
-
214
- return paths.page("/", {
215
- surface: workspaceSurfaceId.value,
216
- params: {
217
- workspaceSlug: normalizedSlug
218
- }
219
- });
220
- }
221
-
222
- function resolveLandingSlug() {
223
- return resolveWorkspaceLandingSlug({
224
- workspaces: workspaceItems.value,
225
- pendingInvites: pendingInvites.value,
226
- lastWorkspaceSlug: readLastWorkspaceSlug(bootstrapModel.userId)
227
- });
228
- }
229
-
230
31
  function workspaceOpenLabel(workspace) {
231
32
  if (!workspace.isAccessible) {
232
33
  return t("jskit.workspaces.workspacesView.unavailable");
@@ -237,178 +38,6 @@ function workspaceOpenLabel(workspace) {
237
38
  function isRespondingToInvite(invite, decision) {
238
39
  return inviteAction.value.token === invite.token && inviteAction.value.decision === decision;
239
40
  }
240
-
241
- async function openWorkspace(workspaceSlug) {
242
- const normalizedSlug = String(workspaceSlug || "").trim();
243
- if (!normalizedSlug) {
244
- return;
245
- }
246
-
247
- const targetPath = workspaceHomePath(normalizedSlug);
248
- if (!targetPath) {
249
- reportFeedback({
250
- message: t("jskit.workspaces.common.surfaceNotConfigured"),
251
- severity: "error",
252
- dedupeKey: "workspaces-web.workspaces-view:workspace-surface-missing"
253
- });
254
- return;
255
- }
256
-
257
- selectingWorkspaceSlug.value = normalizedSlug;
258
-
259
- try {
260
- const navigationTarget = resolveSurfaceNavigationTargetFromPlacementContext(placementContext.value, {
261
- path: targetPath,
262
- surfaceId: workspaceSurfaceId.value
263
- });
264
- if (navigationTarget.sameOrigin && router && typeof router.push === "function") {
265
- await router.push(navigationTarget.href);
266
- } else if (typeof window === "object" && window?.location && typeof window.location.assign === "function") {
267
- window.location.assign(navigationTarget.href);
268
- return;
269
- } else {
270
- throw new Error(t("jskit.workspaces.workspacesView.navigationUnavailable"));
271
- }
272
- } catch (error) {
273
- reportFeedback({
274
- message: errorMessage(error, t("jskit.workspaces.common.openWorkspaceFailed")),
275
- severity: "error",
276
- dedupeKey: `workspaces-web.workspaces-view:open-workspace:${normalizedSlug}`
277
- });
278
- } finally {
279
- selectingWorkspaceSlug.value = "";
280
- }
281
- }
282
-
283
- async function respondToInvite(invite, decision) {
284
- if (!workspaceInvitesEnabled.value) {
285
- return;
286
- }
287
-
288
- const token = String(invite?.token || "").trim();
289
- const normalizedDecision = String(decision || "").trim().toLowerCase();
290
- if (!token || (normalizedDecision !== "accept" && normalizedDecision !== "refuse")) {
291
- return;
292
- }
293
-
294
- inviteAction.value = {
295
- token,
296
- decision: normalizedDecision
297
- };
298
- redeemInviteModel.token = token;
299
- redeemInviteModel.decision = normalizedDecision;
300
-
301
- try {
302
- await redeemInviteCommand.run();
303
-
304
- bootstrapModel.pendingInvites = pendingInvites.value.filter((entry) => entry.token !== token);
305
- await bootstrapView.refresh();
306
-
307
- if (normalizedDecision === "accept") {
308
- const nextWorkspaceSlug = String(invite?.workspaceSlug || "").trim();
309
- if (nextWorkspaceSlug) {
310
- await openWorkspace(nextWorkspaceSlug);
311
- }
312
- return;
313
- }
314
-
315
- reportFeedback({
316
- message: t("jskit.workspaces.common.invitationRefused"),
317
- severity: "success",
318
- dedupeKey: `workspaces-web.workspaces-view:invite-refused:${token}`
319
- });
320
- } catch (error) {
321
- reportFeedback({
322
- message: errorMessage(error, t(normalizedDecision === "accept" ? "jskit.workspaces.workspacesView.acceptFailed" : "jskit.workspaces.workspacesView.refuseFailed")),
323
- severity: "error",
324
- dedupeKey: `workspaces-web.workspaces-view:invite-${normalizedDecision}:${token}`
325
- });
326
- } finally {
327
- inviteAction.value = {
328
- token: "",
329
- decision: ""
330
- };
331
- redeemInviteModel.token = "";
332
- redeemInviteModel.decision = "";
333
- }
334
- }
335
-
336
- function acceptInvite(invite) {
337
- return respondToInvite(invite, "accept");
338
- }
339
-
340
- function refuseInvite(invite) {
341
- return respondToInvite(invite, "refuse");
342
- }
343
-
344
- async function createWorkspace() {
345
- if (!canCreateWorkspace.value) {
346
- return;
347
- }
348
-
349
- const name = String(createWorkspaceModel.name || "").trim();
350
- if (!name) {
351
- reportFeedback({
352
- message: t("jskit.workspaces.workspacesView.nameRequired"),
353
- severity: "error",
354
- dedupeKey: "workspaces-web.workspaces-view:create-workspace-name-required"
355
- });
356
- return;
357
- }
358
-
359
- try {
360
- const createdWorkspace = await createWorkspaceCommand.run();
361
- await bootstrapView.refresh();
362
- const createdSlug = String(createdWorkspace?.slug || "").trim();
363
- const autoOpenHandledByWatcher = Boolean(resolveLandingSlug());
364
- if (createdSlug && !autoOpenHandledByWatcher) {
365
- await openWorkspace(createdSlug);
366
- }
367
- createWorkspaceModel.name = "";
368
- createWorkspaceModel.slug = "";
369
- } catch (error) {
370
- reportFeedback({
371
- message: errorMessage(error, t("jskit.workspaces.workspacesView.createFailed")),
372
- severity: "error",
373
- dedupeKey: "workspaces-web.workspaces-view:create-workspace-error"
374
- });
375
- }
376
- }
377
-
378
- async function refreshBootstrap() {
379
- return bootstrapView.refresh();
380
- }
381
-
382
- watch(
383
- () => bootstrapView.resource.data.value,
384
- async (payload) => {
385
- if (!payload) {
386
- return;
387
- }
388
-
389
- if (!bootstrapModel.sessionAuthenticated) {
390
- const loginTarget = resolveSurfaceNavigationTargetFromPlacementContext(placementContext.value, {
391
- path: "/auth/login",
392
- surfaceId: "auth"
393
- });
394
- if (loginTarget.sameOrigin && router && typeof router.replace === "function") {
395
- await router.replace(loginTarget.href);
396
- } else if (typeof window === "object" && window?.location && typeof window.location.assign === "function") {
397
- window.location.assign(loginTarget.href);
398
- }
399
- return;
400
- }
401
-
402
- const landingSlug = resolveLandingSlug();
403
- if (landingSlug) {
404
- await openWorkspace(landingSlug);
405
- }
406
- },
407
- {
408
- immediate: true
409
- }
410
- );
411
-
412
41
  </script>
413
42
 
414
43
  <template>