@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.
- package/package.descriptor.mjs +507 -0
- package/package.json +31 -0
- package/src/client/components/ConsoleSettingsClientElement.vue +24 -0
- package/src/client/components/MembersAdminClientElement.vue +404 -0
- package/src/client/components/ProfileClientElement.vue +242 -0
- package/src/client/components/UsersProfileSurfaceSwitchMenuItem.vue +39 -0
- package/src/client/components/UsersShellMenuLinkItem.vue +140 -0
- package/src/client/components/UsersSurfaceAwareMenuLinkItem.vue +87 -0
- package/src/client/components/UsersWorkspaceMembersMenuItem.vue +36 -0
- package/src/client/components/UsersWorkspacePermissionMenuItem.vue +90 -0
- package/src/client/components/UsersWorkspaceSelector.vue +237 -0
- package/src/client/components/UsersWorkspaceSettingsMenuItem.vue +39 -0
- package/src/client/components/UsersWorkspaceToolsWidget.vue +23 -0
- package/src/client/components/WorkspaceMembersClientElement.vue +663 -0
- package/src/client/components/WorkspaceSettingsClientElement.vue +230 -0
- package/src/client/components/WorkspacesClientElement.vue +514 -0
- package/src/client/composables/accountSettingsAvatarUploadRuntime.js +241 -0
- package/src/client/composables/accountSettingsInvitesRuntime.js +88 -0
- package/src/client/composables/accountSettingsRuntimeConstants.js +77 -0
- package/src/client/composables/accountSettingsRuntimeHelpers.js +75 -0
- package/src/client/composables/errorMessageHelpers.js +66 -0
- package/src/client/composables/internal/useOperationScope.js +144 -0
- package/src/client/composables/modelStateHelpers.js +49 -0
- package/src/client/composables/operationUiHelpers.js +121 -0
- package/src/client/composables/operationValidationHelpers.js +52 -0
- package/src/client/composables/refValueHelpers.js +19 -0
- package/src/client/composables/scopeHelpers.js +145 -0
- package/src/client/composables/useAccess.js +109 -0
- package/src/client/composables/useAccountSettingsRuntime.js +533 -0
- package/src/client/composables/useAddEdit.js +135 -0
- package/src/client/composables/useAddEditCore.js +137 -0
- package/src/client/composables/useBootstrapQuery.js +52 -0
- package/src/client/composables/useCommand.js +112 -0
- package/src/client/composables/useCommandCore.js +130 -0
- package/src/client/composables/useEndpointResource.js +104 -0
- package/src/client/composables/useFieldErrorBag.js +61 -0
- package/src/client/composables/useList.js +85 -0
- package/src/client/composables/useListCore.js +65 -0
- package/src/client/composables/usePagedCollection.js +125 -0
- package/src/client/composables/usePaths.js +108 -0
- package/src/client/composables/useRealtimeQueryInvalidation.js +105 -0
- package/src/client/composables/useScopeRuntime.js +107 -0
- package/src/client/composables/useSurfaceRouteContext.js +31 -0
- package/src/client/composables/useUiFeedback.js +96 -0
- package/src/client/composables/useView.js +89 -0
- package/src/client/composables/useViewCore.js +104 -0
- package/src/client/composables/useWorkspaceRouteContext.js +28 -0
- package/src/client/composables/useWorkspaceSurfaceId.js +43 -0
- package/src/client/index.js +7 -0
- package/src/client/lib/bootstrap.js +95 -0
- package/src/client/lib/httpClient.js +67 -0
- package/src/client/lib/menuIcons.js +192 -0
- package/src/client/lib/permissions.js +34 -0
- package/src/client/lib/profileSurfaceMenuLinks.js +142 -0
- package/src/client/lib/surfaceAccessPolicy.js +350 -0
- package/src/client/lib/theme.js +99 -0
- package/src/client/lib/workspaceLinkResolver.js +207 -0
- package/src/client/lib/workspaceSurfaceContext.js +82 -0
- package/src/client/lib/workspaceSurfacePaths.js +163 -0
- package/src/client/providers/UsersWebClientProvider.js +85 -0
- package/src/client/runtime/bootstrapPlacementRouteGuards.js +371 -0
- package/src/client/runtime/bootstrapPlacementRuntime.js +413 -0
- package/src/client/runtime/bootstrapPlacementRuntimeConstants.js +32 -0
- package/src/client/runtime/bootstrapPlacementRuntimeHelpers.js +157 -0
- package/src/client/support/contractGuards.js +34 -0
- package/src/client/support/realtimeWorkspace.js +12 -0
- package/src/client/support/runtimeNormalization.js +27 -0
- package/src/client/support/workspaceQueryKeys.js +15 -0
- package/templates/packages/main/src/client/components/AccountPendingInvitesCue.vue +162 -0
- package/templates/src/components/WorkspaceNotFoundCard.vue +33 -0
- package/templates/src/components/account/settings/AccountSettingsClientElement.vue +153 -0
- package/templates/src/components/account/settings/AccountSettingsInvitesSection.vue +77 -0
- package/templates/src/components/account/settings/AccountSettingsNotificationsSection.vue +55 -0
- package/templates/src/components/account/settings/AccountSettingsPreferencesSection.vue +125 -0
- package/templates/src/components/account/settings/AccountSettingsProfileSection.vue +94 -0
- package/templates/src/composables/useWorkspaceNotFoundState.js +48 -0
- package/templates/src/pages/account/index.vue +17 -0
- package/templates/src/pages/admin/members/index.vue +7 -0
- package/templates/src/pages/admin/workspace/settings/index.vue +16 -0
- package/templates/src/pages/console/settings/index.vue +16 -0
- package/templates/src/surfaces/admin/index.vue +29 -0
- package/templates/src/surfaces/admin/root.vue +20 -0
- package/templates/src/surfaces/app/index.vue +27 -0
- package/templates/src/surfaces/app/root.vue +20 -0
- package/test/bootstrap.test.js +38 -0
- package/test/bootstrapPlacementRuntime.test.js +991 -0
- package/test/errorMessageHelpers.test.js +28 -0
- package/test/exportsContract.test.js +39 -0
- package/test/menuIcons.test.js +33 -0
- package/test/permissions.test.js +35 -0
- package/test/profileSurfaceMenuLinks.test.js +207 -0
- package/test/refValueHelpers.test.js +14 -0
- package/test/scopeHelpers.test.js +57 -0
- package/test/surfaceAccessPolicy.test.js +129 -0
- package/test/theme.test.js +95 -0
- package/test/workspaceLinkResolver.test.js +61 -0
- package/test/workspaceSurfacePaths.test.js +39 -0
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { watch } from "vue";
|
|
2
|
+
import { useQueryClient } from "@tanstack/vue-query";
|
|
3
|
+
import { resolveFieldErrors } from "@jskit-ai/http-runtime/client";
|
|
4
|
+
import { validateOperationInput } from "./operationValidationHelpers.js";
|
|
5
|
+
import { captureModelSnapshot, restoreModelSnapshot } from "./modelStateHelpers.js";
|
|
6
|
+
|
|
7
|
+
function useAddEditCore({
|
|
8
|
+
model,
|
|
9
|
+
resource,
|
|
10
|
+
queryKey,
|
|
11
|
+
canSave,
|
|
12
|
+
fieldBag,
|
|
13
|
+
feedback,
|
|
14
|
+
parseInput,
|
|
15
|
+
mapLoadedToModel,
|
|
16
|
+
buildRawPayload,
|
|
17
|
+
buildSavePayload,
|
|
18
|
+
onSaveSuccess,
|
|
19
|
+
messages = {}
|
|
20
|
+
} = {}) {
|
|
21
|
+
const queryClient = useQueryClient();
|
|
22
|
+
const modelSnapshot = captureModelSnapshot(model);
|
|
23
|
+
|
|
24
|
+
watch(
|
|
25
|
+
() => resource?.query?.isPending?.value,
|
|
26
|
+
(isPending) => {
|
|
27
|
+
if (!isPending || !modelSnapshot) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
restoreModelSnapshot(model, modelSnapshot);
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
immediate: true
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
watch(
|
|
39
|
+
() => resource?.data?.value,
|
|
40
|
+
(payload) => {
|
|
41
|
+
if (!payload || typeof mapLoadedToModel !== "function") {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
mapLoadedToModel(model, payload, {
|
|
45
|
+
queryClient,
|
|
46
|
+
resource
|
|
47
|
+
});
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
immediate: true
|
|
51
|
+
}
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
const saving = resource?.isSaving;
|
|
55
|
+
const fieldErrors = fieldBag?.errors;
|
|
56
|
+
const message = feedback?.message;
|
|
57
|
+
const messageType = feedback?.messageType;
|
|
58
|
+
|
|
59
|
+
async function submit() {
|
|
60
|
+
if (!canSave?.value || saving?.value) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
feedback?.clear?.();
|
|
65
|
+
fieldBag?.clear?.();
|
|
66
|
+
|
|
67
|
+
const rawPayload = typeof buildRawPayload === "function" ? buildRawPayload(model, {
|
|
68
|
+
queryClient,
|
|
69
|
+
resource
|
|
70
|
+
}) : {};
|
|
71
|
+
|
|
72
|
+
const validationResult = validateOperationInput({
|
|
73
|
+
parseInput,
|
|
74
|
+
rawPayload,
|
|
75
|
+
context: {
|
|
76
|
+
queryClient,
|
|
77
|
+
resource
|
|
78
|
+
},
|
|
79
|
+
fieldBag,
|
|
80
|
+
feedback,
|
|
81
|
+
validationMessage: String(messages.validation || "Validation failed.")
|
|
82
|
+
});
|
|
83
|
+
if (!validationResult.ok) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const { parseResult, parsedInput } = validationResult;
|
|
88
|
+
const savePayload = typeof buildSavePayload === "function"
|
|
89
|
+
? buildSavePayload(parsedInput, {
|
|
90
|
+
rawPayload,
|
|
91
|
+
queryClient,
|
|
92
|
+
resource
|
|
93
|
+
})
|
|
94
|
+
: parsedInput;
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
const payload = await resource.save(savePayload);
|
|
98
|
+
|
|
99
|
+
if (typeof mapLoadedToModel === "function") {
|
|
100
|
+
mapLoadedToModel(model, payload, {
|
|
101
|
+
queryClient,
|
|
102
|
+
resource
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (queryKey?.value !== undefined) {
|
|
107
|
+
queryClient.setQueryData(queryKey.value, payload);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (typeof onSaveSuccess === "function") {
|
|
111
|
+
await onSaveSuccess(payload, {
|
|
112
|
+
queryClient,
|
|
113
|
+
parsed: parsedInput,
|
|
114
|
+
parseResult,
|
|
115
|
+
rawPayload,
|
|
116
|
+
savePayload,
|
|
117
|
+
resource
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
feedback?.success?.(String(messages.saveSuccess || "Saved."));
|
|
122
|
+
} catch (error) {
|
|
123
|
+
fieldBag?.apply?.(resolveFieldErrors(error));
|
|
124
|
+
feedback?.error?.(error, String(messages.saveError || "Unable to save."));
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return Object.freeze({
|
|
129
|
+
saving,
|
|
130
|
+
fieldErrors,
|
|
131
|
+
message,
|
|
132
|
+
messageType,
|
|
133
|
+
submit
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export { useAddEditCore };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed
|
|
3
|
+
} from "vue";
|
|
4
|
+
import { useQuery } from "@tanstack/vue-query";
|
|
5
|
+
import { normalizeQueryToken } from "@jskit-ai/kernel/shared/support/normalize";
|
|
6
|
+
import { usersWebHttpClient } from "../lib/httpClient.js";
|
|
7
|
+
import { buildBootstrapApiPath } from "../lib/bootstrap.js";
|
|
8
|
+
import { resolveEnabledRef, resolveTextRef } from "./refValueHelpers.js";
|
|
9
|
+
|
|
10
|
+
const DEFAULT_BOOTSTRAP_STALE_TIME_MS = 60_000;
|
|
11
|
+
|
|
12
|
+
function normalizeStaleTime(value, fallback = DEFAULT_BOOTSTRAP_STALE_TIME_MS) {
|
|
13
|
+
const parsed = Number(value);
|
|
14
|
+
if (!Number.isFinite(parsed) || parsed < 0) {
|
|
15
|
+
return fallback;
|
|
16
|
+
}
|
|
17
|
+
return parsed;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function useBootstrapQuery({
|
|
21
|
+
workspaceSlug = "",
|
|
22
|
+
enabled = true,
|
|
23
|
+
staleTime = DEFAULT_BOOTSTRAP_STALE_TIME_MS,
|
|
24
|
+
refetchOnMount = false,
|
|
25
|
+
refetchOnWindowFocus = false
|
|
26
|
+
} = {}) {
|
|
27
|
+
const normalizedWorkspaceSlug = computed(() => resolveTextRef(workspaceSlug));
|
|
28
|
+
const queryKey = computed(() => ["users-web", "bootstrap", normalizeQueryToken(normalizedWorkspaceSlug.value)]);
|
|
29
|
+
const bootstrapPath = computed(() => buildBootstrapApiPath(normalizedWorkspaceSlug.value));
|
|
30
|
+
const queryEnabled = computed(() => resolveEnabledRef(enabled));
|
|
31
|
+
const queryStaleTime = normalizeStaleTime(staleTime, DEFAULT_BOOTSTRAP_STALE_TIME_MS);
|
|
32
|
+
|
|
33
|
+
const query = useQuery({
|
|
34
|
+
queryKey,
|
|
35
|
+
queryFn: () =>
|
|
36
|
+
usersWebHttpClient.request(bootstrapPath.value, {
|
|
37
|
+
method: "GET"
|
|
38
|
+
}),
|
|
39
|
+
enabled: queryEnabled,
|
|
40
|
+
staleTime: queryStaleTime,
|
|
41
|
+
refetchOnMount,
|
|
42
|
+
refetchOnWindowFocus
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
return Object.freeze({
|
|
46
|
+
query,
|
|
47
|
+
queryKey,
|
|
48
|
+
workspaceSlug: normalizedWorkspaceSlug
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { useBootstrapQuery };
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { proxyRefs } from "vue";
|
|
2
|
+
import { USERS_ROUTE_VISIBILITY_WORKSPACE } from "@jskit-ai/users-core/shared/support/usersVisibility";
|
|
3
|
+
import { useCommandCore } from "./useCommandCore.js";
|
|
4
|
+
import { useEndpointResource } from "./useEndpointResource.js";
|
|
5
|
+
import { useOperationScope } from "./internal/useOperationScope.js";
|
|
6
|
+
import { useUiFeedback } from "./useUiFeedback.js";
|
|
7
|
+
import { useFieldErrorBag } from "./useFieldErrorBag.js";
|
|
8
|
+
import {
|
|
9
|
+
setupRouteChangeCleanup,
|
|
10
|
+
setupOperationErrorReporting
|
|
11
|
+
} from "./operationUiHelpers.js";
|
|
12
|
+
|
|
13
|
+
function useCommand({
|
|
14
|
+
ownershipFilter = USERS_ROUTE_VISIBILITY_WORKSPACE,
|
|
15
|
+
surfaceId = "",
|
|
16
|
+
access = "auto",
|
|
17
|
+
apiSuffix = "",
|
|
18
|
+
runPermissions = [],
|
|
19
|
+
writeMethod = "POST",
|
|
20
|
+
placementSource = "users-web.command",
|
|
21
|
+
fallbackRunError = "Unable to complete action.",
|
|
22
|
+
fieldErrorKeys = [],
|
|
23
|
+
clearOnRouteChange = true,
|
|
24
|
+
model,
|
|
25
|
+
parseInput,
|
|
26
|
+
buildRawPayload,
|
|
27
|
+
buildCommandPayload,
|
|
28
|
+
buildCommandOptions,
|
|
29
|
+
onRunSuccess,
|
|
30
|
+
onRunError,
|
|
31
|
+
suppressSuccessMessage = false,
|
|
32
|
+
messages = {},
|
|
33
|
+
realtime = null
|
|
34
|
+
} = {}) {
|
|
35
|
+
const operationScope = useOperationScope({
|
|
36
|
+
ownershipFilter,
|
|
37
|
+
surfaceId,
|
|
38
|
+
access,
|
|
39
|
+
placementSource,
|
|
40
|
+
apiSuffix,
|
|
41
|
+
model,
|
|
42
|
+
readEnabled: false,
|
|
43
|
+
permissionSets: {
|
|
44
|
+
run: runPermissions
|
|
45
|
+
},
|
|
46
|
+
realtime
|
|
47
|
+
});
|
|
48
|
+
const routeContext = operationScope.routeContext;
|
|
49
|
+
const canRun = operationScope.permissionGate("run");
|
|
50
|
+
|
|
51
|
+
const resource = useEndpointResource({
|
|
52
|
+
path: operationScope.apiPath,
|
|
53
|
+
enabled: false,
|
|
54
|
+
writeMethod,
|
|
55
|
+
fallbackSaveError: fallbackRunError
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
const feedback = useUiFeedback({
|
|
59
|
+
source: `${placementSource}.feedback`
|
|
60
|
+
});
|
|
61
|
+
const fieldBag = useFieldErrorBag(fieldErrorKeys);
|
|
62
|
+
|
|
63
|
+
const command = useCommandCore({
|
|
64
|
+
model,
|
|
65
|
+
resource,
|
|
66
|
+
writeMethod,
|
|
67
|
+
canRun,
|
|
68
|
+
fieldBag,
|
|
69
|
+
feedback,
|
|
70
|
+
parseInput,
|
|
71
|
+
buildRawPayload,
|
|
72
|
+
buildCommandPayload,
|
|
73
|
+
buildCommandOptions,
|
|
74
|
+
onRunSuccess,
|
|
75
|
+
onRunError,
|
|
76
|
+
suppressSuccessMessage: Boolean(suppressSuccessMessage),
|
|
77
|
+
messages: {
|
|
78
|
+
validation: "Fix invalid values and try again.",
|
|
79
|
+
success: "Completed.",
|
|
80
|
+
error: String(fallbackRunError || "Unable to complete action."),
|
|
81
|
+
...(messages && typeof messages === "object" ? messages : {})
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
setupRouteChangeCleanup({
|
|
86
|
+
enabled: clearOnRouteChange,
|
|
87
|
+
route: routeContext.route,
|
|
88
|
+
feedback,
|
|
89
|
+
fieldBag
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const loadError = operationScope.loadError();
|
|
93
|
+
const isLoading = operationScope.isLoading();
|
|
94
|
+
setupOperationErrorReporting({
|
|
95
|
+
source: `${placementSource}.load`,
|
|
96
|
+
loadError
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
return proxyRefs({
|
|
100
|
+
canRun,
|
|
101
|
+
isLoading,
|
|
102
|
+
loadError,
|
|
103
|
+
isRunning: command.running,
|
|
104
|
+
fieldErrors: command.fieldErrors,
|
|
105
|
+
message: command.message,
|
|
106
|
+
messageType: command.messageType,
|
|
107
|
+
run: command.run,
|
|
108
|
+
resource
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export { useCommand };
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { useQueryClient } from "@tanstack/vue-query";
|
|
2
|
+
import { resolveFieldErrors } from "@jskit-ai/http-runtime/client";
|
|
3
|
+
import { validateOperationInput } from "./operationValidationHelpers.js";
|
|
4
|
+
|
|
5
|
+
function useCommandCore({
|
|
6
|
+
model,
|
|
7
|
+
resource,
|
|
8
|
+
writeMethod = "POST",
|
|
9
|
+
canRun,
|
|
10
|
+
fieldBag,
|
|
11
|
+
feedback,
|
|
12
|
+
parseInput,
|
|
13
|
+
buildRawPayload,
|
|
14
|
+
buildCommandPayload,
|
|
15
|
+
buildCommandOptions,
|
|
16
|
+
onRunSuccess,
|
|
17
|
+
onRunError,
|
|
18
|
+
suppressSuccessMessage = false,
|
|
19
|
+
messages = {}
|
|
20
|
+
} = {}) {
|
|
21
|
+
const queryClient = useQueryClient();
|
|
22
|
+
const normalizedWriteMethod = String(writeMethod || "POST").trim().toUpperCase();
|
|
23
|
+
|
|
24
|
+
const running = resource?.isSaving;
|
|
25
|
+
const fieldErrors = fieldBag?.errors;
|
|
26
|
+
const message = feedback?.message;
|
|
27
|
+
const messageType = feedback?.messageType;
|
|
28
|
+
|
|
29
|
+
async function run(context = {}) {
|
|
30
|
+
if (!canRun?.value || running?.value) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
feedback?.clear?.();
|
|
35
|
+
fieldBag?.clear?.();
|
|
36
|
+
|
|
37
|
+
const rawPayload = typeof buildRawPayload === "function"
|
|
38
|
+
? buildRawPayload(model, {
|
|
39
|
+
queryClient,
|
|
40
|
+
resource,
|
|
41
|
+
context
|
|
42
|
+
})
|
|
43
|
+
: {};
|
|
44
|
+
|
|
45
|
+
const validationResult = validateOperationInput({
|
|
46
|
+
parseInput,
|
|
47
|
+
rawPayload,
|
|
48
|
+
context: {
|
|
49
|
+
queryClient,
|
|
50
|
+
resource,
|
|
51
|
+
context
|
|
52
|
+
},
|
|
53
|
+
fieldBag,
|
|
54
|
+
feedback,
|
|
55
|
+
validationMessage: String(messages.validation || "Validation failed.")
|
|
56
|
+
});
|
|
57
|
+
if (!validationResult.ok) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const { parseResult, parsedInput } = validationResult;
|
|
62
|
+
const payload = typeof buildCommandPayload === "function"
|
|
63
|
+
? buildCommandPayload(parsedInput, {
|
|
64
|
+
rawPayload,
|
|
65
|
+
queryClient,
|
|
66
|
+
resource,
|
|
67
|
+
context
|
|
68
|
+
})
|
|
69
|
+
: (normalizedWriteMethod === "DELETE" ? undefined : parsedInput);
|
|
70
|
+
|
|
71
|
+
const options = typeof buildCommandOptions === "function"
|
|
72
|
+
? buildCommandOptions(parsedInput, {
|
|
73
|
+
rawPayload,
|
|
74
|
+
queryClient,
|
|
75
|
+
resource,
|
|
76
|
+
context
|
|
77
|
+
})
|
|
78
|
+
: {};
|
|
79
|
+
|
|
80
|
+
try {
|
|
81
|
+
const response = await resource.save(payload, options);
|
|
82
|
+
|
|
83
|
+
if (typeof onRunSuccess === "function") {
|
|
84
|
+
await onRunSuccess(response, {
|
|
85
|
+
parsed: parsedInput,
|
|
86
|
+
parseResult,
|
|
87
|
+
rawPayload,
|
|
88
|
+
payload,
|
|
89
|
+
options,
|
|
90
|
+
queryClient,
|
|
91
|
+
resource,
|
|
92
|
+
context
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!suppressSuccessMessage) {
|
|
97
|
+
feedback?.success?.(String(messages.success || "Completed."));
|
|
98
|
+
}
|
|
99
|
+
return response;
|
|
100
|
+
} catch (error) {
|
|
101
|
+
fieldBag?.apply?.(resolveFieldErrors(error));
|
|
102
|
+
|
|
103
|
+
if (typeof onRunError === "function") {
|
|
104
|
+
await onRunError(error, {
|
|
105
|
+
parsed: parsedInput,
|
|
106
|
+
parseResult,
|
|
107
|
+
rawPayload,
|
|
108
|
+
payload,
|
|
109
|
+
options,
|
|
110
|
+
queryClient,
|
|
111
|
+
resource,
|
|
112
|
+
context
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
feedback?.error?.(error, String(messages.error || "Unable to complete action."));
|
|
117
|
+
throw error;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return Object.freeze({
|
|
122
|
+
running,
|
|
123
|
+
fieldErrors,
|
|
124
|
+
message,
|
|
125
|
+
messageType,
|
|
126
|
+
run
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { useCommandCore };
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { useMutation, useQuery } from "@tanstack/vue-query";
|
|
3
|
+
import { usersWebHttpClient } from "../lib/httpClient.js";
|
|
4
|
+
import { asPlainObject } from "./scopeHelpers.js";
|
|
5
|
+
import { resolveEnabledRef, resolveTextRef } from "./refValueHelpers.js";
|
|
6
|
+
import { toQueryErrorMessage } from "./errorMessageHelpers.js";
|
|
7
|
+
|
|
8
|
+
function useEndpointResource({
|
|
9
|
+
queryKey,
|
|
10
|
+
path = "",
|
|
11
|
+
enabled = true,
|
|
12
|
+
client = usersWebHttpClient,
|
|
13
|
+
readMethod = "GET",
|
|
14
|
+
writeMethod = "PATCH",
|
|
15
|
+
queryOptions = null,
|
|
16
|
+
mutationOptions = null,
|
|
17
|
+
fallbackLoadError = "Unable to load resource.",
|
|
18
|
+
fallbackSaveError = "Unable to save resource."
|
|
19
|
+
} = {}) {
|
|
20
|
+
if (!client || typeof client.request !== "function") {
|
|
21
|
+
throw new TypeError("useEndpointResource requires a client with request().");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const normalizedPath = computed(() => resolveTextRef(path));
|
|
25
|
+
const queryEnabled = computed(() => resolveEnabledRef(enabled) && Boolean(normalizedPath.value));
|
|
26
|
+
|
|
27
|
+
const query = useQuery({
|
|
28
|
+
queryKey,
|
|
29
|
+
queryFn: () => {
|
|
30
|
+
const requestPath = normalizedPath.value;
|
|
31
|
+
if (!requestPath) {
|
|
32
|
+
throw new Error("Resource path is required.");
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return client.request(requestPath, {
|
|
36
|
+
method: String(readMethod || "GET").toUpperCase()
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
enabled: queryEnabled,
|
|
40
|
+
...(asPlainObject(queryOptions))
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const mutation = useMutation({
|
|
44
|
+
mutationFn: async (request = {}) => {
|
|
45
|
+
const options = asPlainObject(request);
|
|
46
|
+
const requestPath = resolveTextRef(options.path || normalizedPath.value);
|
|
47
|
+
if (!requestPath) {
|
|
48
|
+
throw new Error("Resource path is required.");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const method = String(options.method || writeMethod || "PATCH").toUpperCase();
|
|
52
|
+
const hasBody = Object.prototype.hasOwnProperty.call(options, "body");
|
|
53
|
+
const body = hasBody ? options.body : options.payload;
|
|
54
|
+
const requestOptions = {
|
|
55
|
+
method,
|
|
56
|
+
...(asPlainObject(options.options))
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
if (body !== undefined) {
|
|
60
|
+
requestOptions.body = body;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return client.request(requestPath, requestOptions);
|
|
64
|
+
},
|
|
65
|
+
...(asPlainObject(mutationOptions))
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const data = computed(() => query.data.value);
|
|
69
|
+
const isInitialLoading = computed(() => Boolean(queryEnabled.value && query.isPending.value));
|
|
70
|
+
const isFetching = computed(() => Boolean(queryEnabled.value && query.isFetching.value));
|
|
71
|
+
const isRefetching = computed(() => Boolean(isFetching.value && !isInitialLoading.value));
|
|
72
|
+
const isLoading = computed(() => Boolean(isInitialLoading.value || isFetching.value));
|
|
73
|
+
const isSaving = computed(() => Boolean(mutation.isPending.value));
|
|
74
|
+
const loadError = computed(() => toQueryErrorMessage(query.error.value, fallbackLoadError, "Request failed."));
|
|
75
|
+
const saveError = computed(() => toQueryErrorMessage(mutation.error.value, fallbackSaveError, "Request failed."));
|
|
76
|
+
|
|
77
|
+
async function reload() {
|
|
78
|
+
return query.refetch();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function save(payload, options = {}) {
|
|
82
|
+
return mutation.mutateAsync({
|
|
83
|
+
...asPlainObject(options),
|
|
84
|
+
payload
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return Object.freeze({
|
|
89
|
+
query,
|
|
90
|
+
mutation,
|
|
91
|
+
data,
|
|
92
|
+
isInitialLoading,
|
|
93
|
+
isFetching,
|
|
94
|
+
isRefetching,
|
|
95
|
+
isLoading,
|
|
96
|
+
isSaving,
|
|
97
|
+
loadError,
|
|
98
|
+
saveError,
|
|
99
|
+
reload,
|
|
100
|
+
save
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export { useEndpointResource };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { reactive } from "vue";
|
|
2
|
+
|
|
3
|
+
function normalizeKeys(keys) {
|
|
4
|
+
return Array.isArray(keys)
|
|
5
|
+
? keys.map((entry) => String(entry || "").trim()).filter(Boolean)
|
|
6
|
+
: [];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function useFieldErrorBag(keys = []) {
|
|
10
|
+
const normalizedKeys = normalizeKeys(keys);
|
|
11
|
+
const hasFixedKeys = normalizedKeys.length > 0;
|
|
12
|
+
const errors = reactive(
|
|
13
|
+
Object.fromEntries(normalizedKeys.map((key) => [key, ""]))
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
function clear() {
|
|
17
|
+
const keysToClear = hasFixedKeys ? normalizedKeys : Object.keys(errors);
|
|
18
|
+
for (const key of keysToClear) {
|
|
19
|
+
errors[key] = "";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function apply(source = {}) {
|
|
24
|
+
const fieldErrorMap = source && typeof source === "object" ? source : {};
|
|
25
|
+
if (hasFixedKeys) {
|
|
26
|
+
for (const key of normalizedKeys) {
|
|
27
|
+
errors[key] = String(fieldErrorMap[key] || "");
|
|
28
|
+
}
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
clear();
|
|
33
|
+
for (const [field, message] of Object.entries(fieldErrorMap)) {
|
|
34
|
+
const key = String(field || "").trim();
|
|
35
|
+
if (!key) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
errors[key] = String(message || "");
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function set(field, message) {
|
|
43
|
+
const key = String(field || "").trim();
|
|
44
|
+
if (!key) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (hasFixedKeys && !(key in errors)) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
errors[key] = String(message || "");
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return Object.freeze({
|
|
54
|
+
errors,
|
|
55
|
+
clear,
|
|
56
|
+
apply,
|
|
57
|
+
set
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export { useFieldErrorBag };
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { USERS_ROUTE_VISIBILITY_WORKSPACE } from "@jskit-ai/users-core/shared/support/usersVisibility";
|
|
3
|
+
import { useListCore } from "./useListCore.js";
|
|
4
|
+
import { useOperationScope } from "./internal/useOperationScope.js";
|
|
5
|
+
import { setupOperationErrorReporting } from "./operationUiHelpers.js";
|
|
6
|
+
|
|
7
|
+
function useList({
|
|
8
|
+
ownershipFilter = USERS_ROUTE_VISIBILITY_WORKSPACE,
|
|
9
|
+
surfaceId = "",
|
|
10
|
+
access = "auto",
|
|
11
|
+
apiSuffix = "",
|
|
12
|
+
queryKeyFactory = null,
|
|
13
|
+
viewPermissions = [],
|
|
14
|
+
readEnabled = true,
|
|
15
|
+
placementSource = "users-web.list",
|
|
16
|
+
fallbackLoadError = "Unable to load list.",
|
|
17
|
+
initialPageParam = null,
|
|
18
|
+
getNextPageParam,
|
|
19
|
+
selectItems,
|
|
20
|
+
requestOptions,
|
|
21
|
+
queryOptions,
|
|
22
|
+
realtime = null
|
|
23
|
+
} = {}) {
|
|
24
|
+
const operationScope = useOperationScope({
|
|
25
|
+
ownershipFilter,
|
|
26
|
+
surfaceId,
|
|
27
|
+
access,
|
|
28
|
+
placementSource,
|
|
29
|
+
apiSuffix,
|
|
30
|
+
readEnabled,
|
|
31
|
+
queryKeyFactory,
|
|
32
|
+
permissionSets: {
|
|
33
|
+
view: viewPermissions
|
|
34
|
+
},
|
|
35
|
+
realtime
|
|
36
|
+
});
|
|
37
|
+
const canView = operationScope.permissionGate("view");
|
|
38
|
+
|
|
39
|
+
const list = useListCore({
|
|
40
|
+
queryKey: operationScope.queryKey,
|
|
41
|
+
path: operationScope.apiPath,
|
|
42
|
+
enabled: operationScope.queryCanRun(canView),
|
|
43
|
+
initialPageParam,
|
|
44
|
+
getNextPageParam,
|
|
45
|
+
selectItems,
|
|
46
|
+
requestOptions,
|
|
47
|
+
queryOptions,
|
|
48
|
+
fallbackLoadError
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const isInitialLoading = operationScope.isLoading(list.isInitialLoading);
|
|
52
|
+
const isFetching = operationScope.isLoading(list.isFetching);
|
|
53
|
+
const isRefetching = computed(() => Boolean(isFetching.value && !isInitialLoading.value));
|
|
54
|
+
const loadError = operationScope.loadError(list.loadError);
|
|
55
|
+
const isLoading = operationScope.isLoading(list.isLoading);
|
|
56
|
+
setupOperationErrorReporting({
|
|
57
|
+
source: `${placementSource}.load`,
|
|
58
|
+
loadError,
|
|
59
|
+
dedupeWindowMs: 0,
|
|
60
|
+
loadActionFactory: () => ({
|
|
61
|
+
label: "Retry",
|
|
62
|
+
dismissOnRun: true,
|
|
63
|
+
handler() {
|
|
64
|
+
void list.reload();
|
|
65
|
+
}
|
|
66
|
+
})
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return Object.freeze({
|
|
70
|
+
canView,
|
|
71
|
+
isInitialLoading,
|
|
72
|
+
isFetching,
|
|
73
|
+
isRefetching,
|
|
74
|
+
isLoading,
|
|
75
|
+
isLoadingMore: list.isLoadingMore,
|
|
76
|
+
hasMore: list.hasMore,
|
|
77
|
+
loadError,
|
|
78
|
+
pages: list.pages,
|
|
79
|
+
items: list.items,
|
|
80
|
+
reload: list.reload,
|
|
81
|
+
loadMore: list.loadMore
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export { useList };
|