@jskit-ai/users-web 0.1.4

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 (97) hide show
  1. package/package.descriptor.mjs +507 -0
  2. package/package.json +31 -0
  3. package/src/client/components/ConsoleSettingsClientElement.vue +24 -0
  4. package/src/client/components/MembersAdminClientElement.vue +404 -0
  5. package/src/client/components/ProfileClientElement.vue +242 -0
  6. package/src/client/components/UsersProfileSurfaceSwitchMenuItem.vue +39 -0
  7. package/src/client/components/UsersShellMenuLinkItem.vue +140 -0
  8. package/src/client/components/UsersSurfaceAwareMenuLinkItem.vue +87 -0
  9. package/src/client/components/UsersWorkspaceMembersMenuItem.vue +36 -0
  10. package/src/client/components/UsersWorkspacePermissionMenuItem.vue +90 -0
  11. package/src/client/components/UsersWorkspaceSelector.vue +237 -0
  12. package/src/client/components/UsersWorkspaceSettingsMenuItem.vue +39 -0
  13. package/src/client/components/UsersWorkspaceToolsWidget.vue +23 -0
  14. package/src/client/components/WorkspaceMembersClientElement.vue +663 -0
  15. package/src/client/components/WorkspaceSettingsClientElement.vue +230 -0
  16. package/src/client/components/WorkspacesClientElement.vue +514 -0
  17. package/src/client/composables/accountSettingsAvatarUploadRuntime.js +241 -0
  18. package/src/client/composables/accountSettingsInvitesRuntime.js +88 -0
  19. package/src/client/composables/accountSettingsRuntimeConstants.js +77 -0
  20. package/src/client/composables/accountSettingsRuntimeHelpers.js +75 -0
  21. package/src/client/composables/errorMessageHelpers.js +66 -0
  22. package/src/client/composables/internal/useOperationScope.js +144 -0
  23. package/src/client/composables/modelStateHelpers.js +49 -0
  24. package/src/client/composables/operationUiHelpers.js +121 -0
  25. package/src/client/composables/operationValidationHelpers.js +52 -0
  26. package/src/client/composables/refValueHelpers.js +19 -0
  27. package/src/client/composables/scopeHelpers.js +145 -0
  28. package/src/client/composables/useAccess.js +109 -0
  29. package/src/client/composables/useAccountSettingsRuntime.js +533 -0
  30. package/src/client/composables/useAddEdit.js +135 -0
  31. package/src/client/composables/useAddEditCore.js +137 -0
  32. package/src/client/composables/useBootstrapQuery.js +52 -0
  33. package/src/client/composables/useCommand.js +112 -0
  34. package/src/client/composables/useCommandCore.js +130 -0
  35. package/src/client/composables/useEndpointResource.js +104 -0
  36. package/src/client/composables/useFieldErrorBag.js +61 -0
  37. package/src/client/composables/useList.js +85 -0
  38. package/src/client/composables/useListCore.js +65 -0
  39. package/src/client/composables/usePagedCollection.js +125 -0
  40. package/src/client/composables/usePaths.js +108 -0
  41. package/src/client/composables/useRealtimeQueryInvalidation.js +105 -0
  42. package/src/client/composables/useScopeRuntime.js +107 -0
  43. package/src/client/composables/useSurfaceRouteContext.js +31 -0
  44. package/src/client/composables/useUiFeedback.js +96 -0
  45. package/src/client/composables/useView.js +89 -0
  46. package/src/client/composables/useViewCore.js +104 -0
  47. package/src/client/composables/useWorkspaceRouteContext.js +28 -0
  48. package/src/client/composables/useWorkspaceSurfaceId.js +43 -0
  49. package/src/client/index.js +7 -0
  50. package/src/client/lib/bootstrap.js +95 -0
  51. package/src/client/lib/httpClient.js +67 -0
  52. package/src/client/lib/menuIcons.js +192 -0
  53. package/src/client/lib/permissions.js +34 -0
  54. package/src/client/lib/profileSurfaceMenuLinks.js +142 -0
  55. package/src/client/lib/surfaceAccessPolicy.js +350 -0
  56. package/src/client/lib/theme.js +99 -0
  57. package/src/client/lib/workspaceLinkResolver.js +207 -0
  58. package/src/client/lib/workspaceSurfaceContext.js +82 -0
  59. package/src/client/lib/workspaceSurfacePaths.js +163 -0
  60. package/src/client/providers/UsersWebClientProvider.js +85 -0
  61. package/src/client/runtime/bootstrapPlacementRouteGuards.js +371 -0
  62. package/src/client/runtime/bootstrapPlacementRuntime.js +413 -0
  63. package/src/client/runtime/bootstrapPlacementRuntimeConstants.js +32 -0
  64. package/src/client/runtime/bootstrapPlacementRuntimeHelpers.js +157 -0
  65. package/src/client/support/contractGuards.js +34 -0
  66. package/src/client/support/realtimeWorkspace.js +12 -0
  67. package/src/client/support/runtimeNormalization.js +27 -0
  68. package/src/client/support/workspaceQueryKeys.js +15 -0
  69. package/templates/packages/main/src/client/components/AccountPendingInvitesCue.vue +162 -0
  70. package/templates/src/components/WorkspaceNotFoundCard.vue +33 -0
  71. package/templates/src/components/account/settings/AccountSettingsClientElement.vue +153 -0
  72. package/templates/src/components/account/settings/AccountSettingsInvitesSection.vue +77 -0
  73. package/templates/src/components/account/settings/AccountSettingsNotificationsSection.vue +55 -0
  74. package/templates/src/components/account/settings/AccountSettingsPreferencesSection.vue +125 -0
  75. package/templates/src/components/account/settings/AccountSettingsProfileSection.vue +94 -0
  76. package/templates/src/composables/useWorkspaceNotFoundState.js +48 -0
  77. package/templates/src/pages/account/index.vue +17 -0
  78. package/templates/src/pages/admin/members/index.vue +7 -0
  79. package/templates/src/pages/admin/workspace/settings/index.vue +16 -0
  80. package/templates/src/pages/console/settings/index.vue +16 -0
  81. package/templates/src/surfaces/admin/index.vue +29 -0
  82. package/templates/src/surfaces/admin/root.vue +20 -0
  83. package/templates/src/surfaces/app/index.vue +27 -0
  84. package/templates/src/surfaces/app/root.vue +20 -0
  85. package/test/bootstrap.test.js +38 -0
  86. package/test/bootstrapPlacementRuntime.test.js +991 -0
  87. package/test/errorMessageHelpers.test.js +28 -0
  88. package/test/exportsContract.test.js +39 -0
  89. package/test/menuIcons.test.js +33 -0
  90. package/test/permissions.test.js +35 -0
  91. package/test/profileSurfaceMenuLinks.test.js +207 -0
  92. package/test/refValueHelpers.test.js +14 -0
  93. package/test/scopeHelpers.test.js +57 -0
  94. package/test/surfaceAccessPolicy.test.js +129 -0
  95. package/test/theme.test.js +95 -0
  96. package/test/workspaceLinkResolver.test.js +61 -0
  97. package/test/workspaceSurfacePaths.test.js +39 -0
@@ -0,0 +1,49 @@
1
+ function isObjectLike(value) {
2
+ return value !== null && typeof value === "object";
3
+ }
4
+
5
+ function deepClone(value) {
6
+ try {
7
+ return JSON.parse(JSON.stringify(value));
8
+ } catch {
9
+ return null;
10
+ }
11
+ }
12
+
13
+ function captureModelSnapshot(model) {
14
+ if (!isObjectLike(model)) {
15
+ return null;
16
+ }
17
+
18
+ return deepClone(model);
19
+ }
20
+
21
+ function restoreModelSnapshot(model, snapshot) {
22
+ if (!isObjectLike(model) || !isObjectLike(snapshot)) {
23
+ return;
24
+ }
25
+
26
+ if (Array.isArray(model) && Array.isArray(snapshot)) {
27
+ model.splice(0, model.length, ...snapshot);
28
+ return;
29
+ }
30
+
31
+ if (Array.isArray(model) || Array.isArray(snapshot)) {
32
+ return;
33
+ }
34
+
35
+ for (const key of Object.keys(model)) {
36
+ if (!Object.prototype.hasOwnProperty.call(snapshot, key)) {
37
+ delete model[key];
38
+ }
39
+ }
40
+
41
+ for (const [key, value] of Object.entries(snapshot)) {
42
+ model[key] = value;
43
+ }
44
+ }
45
+
46
+ export {
47
+ captureModelSnapshot,
48
+ restoreModelSnapshot
49
+ };
@@ -0,0 +1,121 @@
1
+ import { watch } from "vue";
2
+ import { useShellWebErrorRuntime } from "@jskit-ai/shell-web/client/error";
3
+
4
+ function normalizeMessage(value) {
5
+ return String(value || "").trim();
6
+ }
7
+
8
+ function setupOperationErrorReporting({
9
+ enabled = true,
10
+ source = "users-web.operation",
11
+ loadError = null,
12
+ notFoundError = null,
13
+ loadActionFactory = null,
14
+ notFoundActionFactory = null,
15
+ loadChannel = "banner",
16
+ notFoundChannel = "banner",
17
+ loadSeverity = "error",
18
+ notFoundSeverity = "warning",
19
+ dedupeWindowMs = 2000
20
+ } = {}) {
21
+ if (!enabled) {
22
+ return;
23
+ }
24
+
25
+ const runtime = useShellWebErrorRuntime();
26
+ const normalizedSource = normalizeMessage(source) || "users-web.operation";
27
+
28
+ function watchMessage(value, {
29
+ kind = "load",
30
+ channel = "banner",
31
+ severity = "error",
32
+ actionFactory = null
33
+ } = {}) {
34
+ let lastMessage = "";
35
+ let lastPresentationId = "";
36
+
37
+ watch(
38
+ () => normalizeMessage(value?.value),
39
+ (nextMessage) => {
40
+ if (!nextMessage) {
41
+ lastMessage = "";
42
+ if (lastPresentationId) {
43
+ runtime.dismiss(lastPresentationId);
44
+ lastPresentationId = "";
45
+ }
46
+ return;
47
+ }
48
+
49
+ if (nextMessage === lastMessage) {
50
+ return;
51
+ }
52
+
53
+ lastMessage = nextMessage;
54
+ const action = typeof actionFactory === "function"
55
+ ? actionFactory({
56
+ message: nextMessage,
57
+ kind
58
+ })
59
+ : null;
60
+ const reportResult = runtime.report({
61
+ source: normalizedSource,
62
+ message: nextMessage,
63
+ severity,
64
+ channel,
65
+ action,
66
+ dedupeKey: `${normalizedSource}:${kind}:${nextMessage}`,
67
+ dedupeWindowMs
68
+ });
69
+
70
+ const nextPresentationId = String(reportResult?.presentationId || "").trim();
71
+ if (nextPresentationId) {
72
+ if (lastPresentationId && lastPresentationId !== nextPresentationId) {
73
+ runtime.dismiss(lastPresentationId);
74
+ }
75
+ lastPresentationId = nextPresentationId;
76
+ }
77
+ },
78
+ { immediate: true }
79
+ );
80
+ }
81
+
82
+ if (loadError) {
83
+ watchMessage(loadError, {
84
+ kind: "load",
85
+ channel: loadChannel,
86
+ severity: loadSeverity,
87
+ actionFactory: loadActionFactory
88
+ });
89
+ }
90
+
91
+ if (notFoundError) {
92
+ watchMessage(notFoundError, {
93
+ kind: "not-found",
94
+ channel: notFoundChannel,
95
+ severity: notFoundSeverity,
96
+ actionFactory: notFoundActionFactory
97
+ });
98
+ }
99
+ }
100
+
101
+ function setupRouteChangeCleanup({
102
+ enabled = true,
103
+ route = null,
104
+ feedback = null,
105
+ fieldBag = null
106
+ } = {}) {
107
+ if (!enabled) {
108
+ return;
109
+ }
110
+
111
+ watch(
112
+ () => route?.fullPath,
113
+ () => {
114
+ feedback?.clear?.();
115
+ fieldBag?.clear?.();
116
+ }
117
+ );
118
+ }
119
+
120
+ export { setupRouteChangeCleanup };
121
+ export { setupOperationErrorReporting };
@@ -0,0 +1,52 @@
1
+ import {
2
+ createValidationFailure,
3
+ resolveFieldErrors
4
+ } from "@jskit-ai/http-runtime/client";
5
+
6
+ function validateOperationInput({
7
+ parseInput,
8
+ rawPayload = {},
9
+ context = {},
10
+ fieldBag = null,
11
+ feedback = null,
12
+ validationMessage = "Validation failed."
13
+ } = {}) {
14
+ if (typeof parseInput !== "function") {
15
+ return {
16
+ ok: true,
17
+ parseResult: null,
18
+ parsedInput: rawPayload
19
+ };
20
+ }
21
+
22
+ const parseResult = parseInput(rawPayload, context);
23
+ if (!parseResult || typeof parseResult !== "object" || typeof parseResult.ok !== "boolean") {
24
+ throw new TypeError(
25
+ "parseInput(rawPayload, context) must return validateOperationSection-compatible result with boolean ok."
26
+ );
27
+ }
28
+
29
+ if (!parseResult.ok) {
30
+ const failure = createValidationFailure({
31
+ error: String(validationMessage || "Validation failed."),
32
+ code: "validation_failed",
33
+ fieldErrors: parseResult.fieldErrors
34
+ });
35
+ fieldBag?.apply?.(resolveFieldErrors(failure));
36
+ feedback?.error?.(failure, failure.error);
37
+ return {
38
+ ok: false,
39
+ failure,
40
+ parseResult,
41
+ parsedInput: null
42
+ };
43
+ }
44
+
45
+ return {
46
+ ok: true,
47
+ parseResult,
48
+ parsedInput: parseResult.value
49
+ };
50
+ }
51
+
52
+ export { validateOperationInput };
@@ -0,0 +1,19 @@
1
+ import { unref } from "vue";
2
+
3
+ function resolveEnabledRef(value) {
4
+ if (value === undefined) {
5
+ return true;
6
+ }
7
+
8
+ if (typeof value === "function") {
9
+ return Boolean(value());
10
+ }
11
+
12
+ return Boolean(unref(value));
13
+ }
14
+
15
+ function resolveTextRef(value) {
16
+ return String(unref(value) || "").trim();
17
+ }
18
+
19
+ export { resolveEnabledRef, resolveTextRef };
@@ -0,0 +1,145 @@
1
+ import { resolveEnabledRef, resolveTextRef } from "./refValueHelpers.js";
2
+ import {
3
+ USERS_ROUTE_VISIBILITY_LEVELS,
4
+ USERS_ROUTE_VISIBILITY_WORKSPACE,
5
+ USERS_ROUTE_VISIBILITY_WORKSPACE_USER
6
+ } from "@jskit-ai/users-core/shared/support/usersVisibility";
7
+
8
+ const USERS_OWNERSHIP_FILTER_VALUES = USERS_ROUTE_VISIBILITY_LEVELS;
9
+ const WORKSPACE_OWNERSHIP_FILTER_SET = new Set([
10
+ USERS_ROUTE_VISIBILITY_WORKSPACE,
11
+ USERS_ROUTE_VISIBILITY_WORKSPACE_USER
12
+ ]);
13
+ const ACCESS_MODE_VALUES = Object.freeze(["auto", "always", "never"]);
14
+
15
+ function asPlainObject(value) {
16
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
17
+ return {};
18
+ }
19
+
20
+ return value;
21
+ }
22
+
23
+ function normalizePermissions(value) {
24
+ if (Array.isArray(value)) {
25
+ return value.map((entry) => String(entry || "").trim()).filter(Boolean);
26
+ }
27
+
28
+ const one = String(value || "").trim();
29
+ return one ? [one] : [];
30
+ }
31
+
32
+ function resolvePermissionAccess(access, normalizedPermissions = []) {
33
+ if (normalizedPermissions.length < 1) {
34
+ return true;
35
+ }
36
+
37
+ return access.canAny(normalizedPermissions);
38
+ }
39
+
40
+ function normalizeAccessMode(value = "auto") {
41
+ const normalized = String(value || "auto").trim().toLowerCase();
42
+ if (ACCESS_MODE_VALUES.includes(normalized)) {
43
+ return normalized;
44
+ }
45
+
46
+ throw new TypeError(
47
+ `access must be one of: ${ACCESS_MODE_VALUES.join(", ")}. Received: ${String(value || "") || "(empty)"}`
48
+ );
49
+ }
50
+
51
+ function resolveAccessModeEnabled(accessMode = "auto", { hasPermissionRequirements = false } = {}) {
52
+ const normalizedMode = normalizeAccessMode(accessMode);
53
+ if (normalizedMode === "always") {
54
+ return true;
55
+ }
56
+ if (normalizedMode === "never") {
57
+ return false;
58
+ }
59
+
60
+ return hasPermissionRequirements === true;
61
+ }
62
+
63
+ function ensureAccessModeCompatibility({
64
+ accessMode = "auto",
65
+ hasPermissionRequirements = false,
66
+ caller = "users-web"
67
+ } = {}) {
68
+ const normalizedMode = normalizeAccessMode(accessMode);
69
+ if (normalizedMode === "never" && hasPermissionRequirements) {
70
+ throw new TypeError(`${caller} cannot use access:\"never\" when permission requirements are configured.`);
71
+ }
72
+
73
+ return normalizedMode;
74
+ }
75
+
76
+ function resolveApiSuffix(apiSuffix, context = {}) {
77
+ if (typeof apiSuffix === "function") {
78
+ return resolveTextRef(apiSuffix(context));
79
+ }
80
+
81
+ return resolveTextRef(apiSuffix);
82
+ }
83
+
84
+ function resolveEnabled(value, context = {}) {
85
+ if (typeof value === "function") {
86
+ return Boolean(value(context));
87
+ }
88
+
89
+ return resolveEnabledRef(value);
90
+ }
91
+
92
+ function normalizeOwnershipFilter(value = USERS_ROUTE_VISIBILITY_WORKSPACE) {
93
+ const normalized = String(value || USERS_ROUTE_VISIBILITY_WORKSPACE).trim().toLowerCase();
94
+ if (USERS_OWNERSHIP_FILTER_VALUES.includes(normalized)) {
95
+ return normalized;
96
+ }
97
+
98
+ throw new TypeError(
99
+ `ownershipFilter must be one of: ${USERS_OWNERSHIP_FILTER_VALUES.join(", ")}. Received: ${String(value || "") || "(empty)"}`
100
+ );
101
+ }
102
+
103
+ function isWorkspaceOwnershipFilter(ownershipFilter) {
104
+ return WORKSPACE_OWNERSHIP_FILTER_SET.has(ownershipFilter);
105
+ }
106
+
107
+ function resolveQueryKey(
108
+ queryKeyFactory,
109
+ { surfaceId = "", workspaceSlug = "", ownershipFilter = USERS_ROUTE_VISIBILITY_WORKSPACE } = {}
110
+ ) {
111
+ if (typeof queryKeyFactory !== "function") {
112
+ throw new TypeError("queryKeyFactory is required.");
113
+ }
114
+
115
+ if (isWorkspaceOwnershipFilter(ownershipFilter)) {
116
+ return queryKeyFactory(surfaceId, workspaceSlug, ownershipFilter);
117
+ }
118
+
119
+ return queryKeyFactory(surfaceId, ownershipFilter);
120
+ }
121
+
122
+ function resolveResourceMessages(resource, defaults = {}) {
123
+ const defaultMessages = asPlainObject(defaults);
124
+ const resourceMessages = asPlainObject(asPlainObject(resource).messages);
125
+
126
+ return {
127
+ ...defaultMessages,
128
+ ...resourceMessages
129
+ };
130
+ }
131
+
132
+ export {
133
+ asPlainObject,
134
+ normalizePermissions,
135
+ resolvePermissionAccess,
136
+ normalizeAccessMode,
137
+ resolveAccessModeEnabled,
138
+ ensureAccessModeCompatibility,
139
+ resolveApiSuffix,
140
+ resolveEnabled,
141
+ normalizeOwnershipFilter,
142
+ isWorkspaceOwnershipFilter,
143
+ resolveQueryKey,
144
+ resolveResourceMessages
145
+ };
@@ -0,0 +1,109 @@
1
+ import { computed } from "vue";
2
+ import { hasPermission, normalizePermissionList } from "../lib/permissions.js";
3
+ import { resolveEnabledRef, resolveTextRef } from "./refValueHelpers.js";
4
+ import {
5
+ normalizeAccessMode,
6
+ resolveAccessModeEnabled
7
+ } from "./scopeHelpers.js";
8
+ import { useWebPlacementContext } from "@jskit-ai/shell-web/client/placement";
9
+
10
+ function asPermissionList(value) {
11
+ if (Array.isArray(value)) {
12
+ return value;
13
+ }
14
+
15
+ if (value === undefined || value === null || value === "") {
16
+ return [];
17
+ }
18
+
19
+ return [value];
20
+ }
21
+
22
+ function useAccess({
23
+ workspaceSlug = "",
24
+ enabled = true,
25
+ access = "always",
26
+ hasPermissionRequirements = false
27
+ } = {}) {
28
+ const normalizedAccessMode = normalizeAccessMode(access);
29
+ const accessRequired = resolveAccessModeEnabled(normalizedAccessMode, {
30
+ hasPermissionRequirements: hasPermissionRequirements === true
31
+ });
32
+ const { context: placementContext } = useWebPlacementContext();
33
+ const normalizedWorkspaceSlug = computed(() => resolveTextRef(workspaceSlug));
34
+ const queryEnabled = computed(() => resolveEnabledRef(enabled) && accessRequired);
35
+ const hasPlacementBootstrapPermissions = computed(() => {
36
+ const source = placementContext.value;
37
+ if (!source || typeof source !== "object") {
38
+ return false;
39
+ }
40
+ return Object.hasOwn(source, "permissions");
41
+ });
42
+ const placementPermissions = computed(() => normalizePermissionList(placementContext.value?.permissions));
43
+ const permissions = computed(() => {
44
+ if (!queryEnabled.value || !hasPlacementBootstrapPermissions.value) {
45
+ return [];
46
+ }
47
+ return placementPermissions.value;
48
+ });
49
+ const bootstrapError = computed(() => {
50
+ if (!queryEnabled.value || hasPlacementBootstrapPermissions.value) {
51
+ return "";
52
+ }
53
+ return "Permissions are unavailable in placement context.";
54
+ });
55
+ const isBootstrapping = computed(() => queryEnabled.value && !hasPlacementBootstrapPermissions.value);
56
+
57
+ function can(permission) {
58
+ return hasPermission(permissions.value, permission);
59
+ }
60
+
61
+ function canAny(requiredPermissions) {
62
+ const list = asPermissionList(requiredPermissions);
63
+ if (list.length < 1) {
64
+ return true;
65
+ }
66
+
67
+ for (const entry of list) {
68
+ if (can(entry)) {
69
+ return true;
70
+ }
71
+ }
72
+
73
+ return false;
74
+ }
75
+
76
+ function canAll(requiredPermissions) {
77
+ const list = asPermissionList(requiredPermissions);
78
+ if (list.length < 1) {
79
+ return true;
80
+ }
81
+
82
+ for (const entry of list) {
83
+ if (!can(entry)) {
84
+ return false;
85
+ }
86
+ }
87
+
88
+ return true;
89
+ }
90
+
91
+ async function refreshBootstrap() {
92
+ return null;
93
+ }
94
+
95
+ return Object.freeze({
96
+ accessMode: normalizedAccessMode,
97
+ accessRequired,
98
+ workspaceSlug: normalizedWorkspaceSlug,
99
+ permissions,
100
+ bootstrapError,
101
+ isBootstrapping,
102
+ can,
103
+ canAny,
104
+ canAll,
105
+ refreshBootstrap
106
+ });
107
+ }
108
+
109
+ export { useAccess };