@krak-stack/auth 0.2.31 → 0.3.0
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/CHANGELOG.md +19 -0
- package/README.md +175 -1
- package/dist/access.d.ts +3 -1
- package/dist/admin/api.group.d.ts +41 -41
- package/dist/admin/schema.d.ts +23 -23
- package/dist/admin/schema.js +21 -19
- package/dist/api.d.ts +141 -81
- package/dist/auth/api.group.d.ts +37 -19
- package/dist/auth/api.group.js +17 -1
- package/dist/auth/schema.d.ts +61 -33
- package/dist/auth/schema.js +30 -18
- package/dist/components/account-deletion-request.d.ts +5 -0
- package/dist/components/account-deletion-request.js +7 -0
- package/dist/components/account-deletion.d.ts +8 -0
- package/dist/components/account-deletion.js +59 -0
- package/dist/components/admin-organization-form.js +2 -2
- package/dist/components/admin-organizations.js +9 -7
- package/dist/components/admin-users.js +6 -6
- package/dist/components/api-key-edit-form.js +19 -11
- package/dist/components/associated-projects-notice.d.ts +2 -1
- package/dist/components/associated-projects-notice.js +7 -3
- package/dist/components/auth-atoms.js +1 -2
- package/dist/components/auth-client-api.d.ts +94 -61
- package/dist/components/auth-forms.d.ts +1 -0
- package/dist/components/auth-forms.js +41 -56
- package/dist/components/auth-provider.d.ts +3 -1
- package/dist/components/deletion-visibility.d.ts +1 -0
- package/dist/components/deletion-visibility.js +3 -0
- package/dist/components/hooks.d.ts +2 -0
- package/dist/components/hooks.js +13 -6
- package/dist/components/index.d.ts +3 -0
- package/dist/components/index.js +2 -0
- package/dist/components/member-required.js +3 -5
- package/dist/components/oauth-consent.d.ts +22 -0
- package/dist/components/oauth-consent.js +79 -0
- package/dist/components/organization-deletion-request.d.ts +17 -0
- package/dist/components/organization-deletion-request.js +9 -0
- package/dist/components/organization-switcher.d.ts +1 -1
- package/dist/components/organization-switcher.js +113 -55
- package/dist/components/project-card-list.d.ts +6 -0
- package/dist/components/project-card-list.js +4 -0
- package/dist/components/user-button.d.ts +29 -1
- package/dist/components/user-button.js +145 -47
- package/dist/extra/api.group.d.ts +13 -1
- package/dist/extra/api.group.js +5 -1
- package/dist/extra/schema.d.ts +16 -1
- package/dist/extra/schema.js +13 -0
- package/dist/oauth/authorization.d.ts +3 -0
- package/dist/oauth/authorization.js +39 -0
- package/dist/oauth/schema.d.ts +24 -0
- package/dist/oauth/schema.js +12 -0
- package/dist/oauth/verify.d.ts +13 -0
- package/dist/oauth/verify.js +67 -0
- package/dist/schema.d.ts +35 -0
- package/dist/schema.js +26 -1
- package/dist/server/actor.js +2 -4
- package/dist/server/index.d.ts +4 -1
- package/dist/server/index.js +2 -0
- package/dist/server/mcp.d.ts +20 -0
- package/dist/server/mcp.js +66 -0
- package/dist/server/middleware.d.ts +15 -7
- package/dist/server/middleware.js +19 -6
- package/dist/server/webhook-layer.d.ts +6 -0
- package/dist/server/webhook-layer.js +41 -0
- package/dist/server/webhooks.d.ts +44 -0
- package/dist/server/webhooks.js +39 -0
- package/dist/service.d.ts +118 -46
- package/dist/service.js +56 -9
- package/package.json +8 -3
|
@@ -90,9 +90,9 @@ const makeOrganizationForm = ({ baseUrl, organization, }) => FormReact.make(orga
|
|
|
90
90
|
slug: slugify(decoded.slug || decoded.name),
|
|
91
91
|
logo: logo ?? undefined,
|
|
92
92
|
};
|
|
93
|
-
const payload = Schema.
|
|
93
|
+
const payload = yield* Schema.decodeEffect(AdminCreateOrganizationPayload)(decoded.parentId === noParentOrganization
|
|
94
94
|
? input
|
|
95
|
-
: { ...input, parentId: decoded.parentId });
|
|
95
|
+
: { ...input, parentId: decoded.parentId }).pipe(Effect.orDie);
|
|
96
96
|
const saved = organization
|
|
97
97
|
? yield* http.admin.updateOrganization({
|
|
98
98
|
params: { id: organization.id },
|
|
@@ -13,6 +13,8 @@ import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent,
|
|
|
13
13
|
import { AdminListQuery } from "../admin/schema.js";
|
|
14
14
|
import { normalizeOrganizationRoles } from "../roles.js";
|
|
15
15
|
import { AdminOrganizationForm } from "./admin-organization-form.js";
|
|
16
|
+
import { ProjectCardList } from "./project-card-list.js";
|
|
17
|
+
import { deletionControlsEnabled } from "./deletion-visibility.js";
|
|
16
18
|
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
17
19
|
import { useKrakstackAuth } from "./auth-provider.js";
|
|
18
20
|
import { assetUrl, organizationBranding } from "./utils.js";
|
|
@@ -98,7 +100,7 @@ const organizationDisplay = (organization, locale, baseUrl) => {
|
|
|
98
100
|
};
|
|
99
101
|
const AdminOrganizationsFamilyKey = Schema.fromJsonString(Schema.Struct({
|
|
100
102
|
query: AdminListQuery,
|
|
101
|
-
reloadKey: Schema.
|
|
103
|
+
reloadKey: Schema.Finite,
|
|
102
104
|
})).annotate({ identifier: "AdminOrganizationsFamilyKey" });
|
|
103
105
|
const organizationsQuery = (search, projectId) => projectId ? { ...search, projectId } : search;
|
|
104
106
|
const adminOrganizationsFamilyKey = (search, projectId, reloadKey) => JSON.stringify({
|
|
@@ -106,7 +108,7 @@ const adminOrganizationsFamilyKey = (search, projectId, reloadKey) => JSON.strin
|
|
|
106
108
|
reloadKey,
|
|
107
109
|
});
|
|
108
110
|
const organizationsAtom = Atom.family((baseUrl) => Atom.family((key) => {
|
|
109
|
-
const { query, reloadKey } = Schema.
|
|
111
|
+
const { query, reloadKey } = Schema.decodeSync(AdminOrganizationsFamilyKey)(key);
|
|
110
112
|
return authClientApi(baseUrl).query("admin", "listOrganizations", {
|
|
111
113
|
query,
|
|
112
114
|
timeToLive: "1 minute",
|
|
@@ -165,7 +167,7 @@ export function AdminOrganizationsTable({ messages: messageOverrides, onSearchCh
|
|
|
165
167
|
projectId,
|
|
166
168
|
reloadKey,
|
|
167
169
|
refreshKey: 0,
|
|
168
|
-
search: search ?? Schema.
|
|
170
|
+
search: search ?? Schema.decodeSync(Query)({}),
|
|
169
171
|
}));
|
|
170
172
|
const setTableRequest = useAtomSet(tableAtoms.requestAtom);
|
|
171
173
|
const tableRequest = useAtomValue(tableAtoms.requestAtom);
|
|
@@ -220,12 +222,12 @@ export function AdminOrganizationsTable({ messages: messageOverrides, onSearchCh
|
|
|
220
222
|
icon: _jsx(Trash2, { className: "size-4" }),
|
|
221
223
|
variant: "destructive",
|
|
222
224
|
onClick: setDeletingOrganization,
|
|
223
|
-
visible: (organization) => !organization.userId,
|
|
225
|
+
visible: (organization) => deletionControlsEnabled && !organization.userId,
|
|
224
226
|
},
|
|
225
227
|
],
|
|
226
228
|
},
|
|
227
229
|
}, state: tableRequest.search, onStateChange: ({ page, pageSize, globalFilter, sort, filters }) => {
|
|
228
|
-
const nextSearch = Schema.
|
|
230
|
+
const nextSearch = Schema.decodeSync(Query)({
|
|
229
231
|
page,
|
|
230
232
|
pageSize,
|
|
231
233
|
globalFilter,
|
|
@@ -242,7 +244,7 @@ export function AdminOrganizationsTable({ messages: messageOverrides, onSearchCh
|
|
|
242
244
|
}, status: { loading: isLoading } }), editingOrganization ? (_jsx(AdminOrganizationForm, { organization: editingOrganization, onClose: () => setEditingOrganization(null), onSaved: () => setTableRequest((current) => ({
|
|
243
245
|
...current,
|
|
244
246
|
refreshKey: current.refreshKey + 1,
|
|
245
|
-
})) })) : null, deletingOrganization ? (_jsx(DeleteOrganizationDialog, { labels: m, organization: deletingOrganization, baseUrl: baseUrl, onClose: () => setDeletingOrganization(null), onDeleted: () => {
|
|
247
|
+
})) })) : null, deletionControlsEnabled && deletingOrganization ? (_jsx(DeleteOrganizationDialog, { labels: m, organization: deletingOrganization, baseUrl: baseUrl, onClose: () => setDeletingOrganization(null), onDeleted: () => {
|
|
246
248
|
setDeletingOrganization(null);
|
|
247
249
|
setTableRequest((current) => ({
|
|
248
250
|
...current,
|
|
@@ -356,7 +358,7 @@ function DeleteOrganizationDialog({ baseUrl, labels: m, organization, onClose, o
|
|
|
356
358
|
? Cause.squash(result.cause)
|
|
357
359
|
: undefined;
|
|
358
360
|
const isPending = !AsyncResult.isInitial(result) && result.waiting;
|
|
359
|
-
return (_jsx(AlertDialog, { open: true, onOpenChange: (open) => !open && onClose(), children: _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: m.organization_delete_title }), _jsx(AlertDialogDescription, { children: m.organization_delete_description.replace("{name}", organization.name) })] }), error ? (_jsx(ErrorMessage, { text: error instanceof Error
|
|
361
|
+
return (_jsx(AlertDialog, { open: true, onOpenChange: (open) => !open && onClose(), children: _jsxs(AlertDialogContent, { className: "max-h-[85vh] overflow-y-auto sm:max-w-xl", children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: m.organization_delete_title }), _jsx(AlertDialogDescription, { children: m.organization_delete_description.replace("{name}", organization.name) })] }), organization.projects?.length ? (_jsxs("section", { className: "space-y-2", children: [_jsxs("h3", { className: "text-muted-foreground text-xs font-medium", children: [m.admin_column_projects, " ", _jsx("span", { className: "ml-1 tabular-nums", children: organization.projects.length })] }), _jsx(ProjectCardList, { projects: organization.projects })] })) : null, error ? (_jsx(ErrorMessage, { text: error instanceof Error
|
|
360
362
|
? error.message
|
|
361
363
|
: m.organization_delete_error })) : null, _jsxs(AlertDialogFooter, { children: [_jsx(AlertDialogCancel, { disabled: isPending, children: m.organization_delete_cancel }), _jsx(AlertDialogAction, { disabled: isPending, onClick: (event) => {
|
|
362
364
|
event.preventDefault();
|
|
@@ -83,12 +83,12 @@ const initials = (name) => name
|
|
|
83
83
|
const text = (value, params) => Object.entries(params ?? {}).reduce((current, [key, replacement]) => current.replace(`{${key}}`, replacement), value);
|
|
84
84
|
const AdminUsersFamilyKey = Schema.fromJsonString(Schema.Struct({
|
|
85
85
|
query: AdminListQuery,
|
|
86
|
-
reloadKey: Schema.
|
|
86
|
+
reloadKey: Schema.Finite,
|
|
87
87
|
})).annotate({ identifier: "AdminUsersFamilyKey" });
|
|
88
88
|
const adminUsersQuery = (search, projectId) => projectId ? { ...search, projectId } : search;
|
|
89
89
|
const adminUsersFamilyKey = (search, projectId, reloadKey) => JSON.stringify({ query: adminUsersQuery(search, projectId), reloadKey });
|
|
90
90
|
const usersAtom = Atom.family((baseUrl) => Atom.family((key) => {
|
|
91
|
-
const { query, reloadKey } = Schema.
|
|
91
|
+
const { query, reloadKey } = Schema.decodeSync(AdminUsersFamilyKey)(key);
|
|
92
92
|
return authClientApi(baseUrl).query("admin", "listUsers", {
|
|
93
93
|
query,
|
|
94
94
|
timeToLive: "1 minute",
|
|
@@ -118,7 +118,7 @@ export function AdminUsersTable({ onSearchChange, reloadKey = 0, search, }) {
|
|
|
118
118
|
projectId,
|
|
119
119
|
reloadKey,
|
|
120
120
|
refreshKey: 0,
|
|
121
|
-
search: search ?? Schema.
|
|
121
|
+
search: search ?? Schema.decodeSync(Query)({}),
|
|
122
122
|
}));
|
|
123
123
|
const setTableRequest = useAtomSet(tableAtoms.requestAtom);
|
|
124
124
|
const tableRequest = useAtomValue(tableAtoms.requestAtom);
|
|
@@ -200,7 +200,7 @@ export function AdminUsersTable({ onSearchChange, reloadKey = 0, search, }) {
|
|
|
200
200
|
],
|
|
201
201
|
},
|
|
202
202
|
}, state: tableRequest.search, onStateChange: ({ page, pageSize, globalFilter, sort, filters }) => {
|
|
203
|
-
const nextSearch = Schema.
|
|
203
|
+
const nextSearch = Schema.decodeSync(Query)({
|
|
204
204
|
page,
|
|
205
205
|
pageSize,
|
|
206
206
|
globalFilter,
|
|
@@ -322,8 +322,8 @@ const userColumns = (m, baseUrl) => [
|
|
|
322
322
|
},
|
|
323
323
|
];
|
|
324
324
|
function BanUserDialog({ labels: m, baseUrl, user, onBanned, onClose, }) {
|
|
325
|
-
const [banUserAtom] = useState(() => authClientApi(baseUrl).runtime.fn((userId) => Effect.flatMap(authHttpClient(baseUrl), (client) => client.auth.adminBanUser({ payload: { userId } })).pipe(Effect.tap(() => Effect.sync(onBanned)), Effect.tap(() => Effect.sync(onClose)), Effect.catch((cause) => Effect.sync(() => setError(cause instanceof Error ? cause.message : m.admin_error_ban))))));
|
|
326
325
|
const [error, setError] = useState("");
|
|
326
|
+
const [banUserAtom] = useState(() => authClientApi(baseUrl).runtime.fn((userId) => Effect.flatMap(authHttpClient(baseUrl), (client) => client.auth.adminBanUser({ payload: { userId } })).pipe(Effect.tap(() => Effect.sync(onBanned)), Effect.tap(() => Effect.sync(onClose)), Effect.catch((cause) => Effect.sync(() => setError(cause instanceof Error ? cause.message : m.admin_error_ban))))));
|
|
327
327
|
const banUser = useAtomSet(banUserAtom);
|
|
328
328
|
const isPending = useAtomValue(banUserAtom).waiting;
|
|
329
329
|
return (_jsx(AlertDialog, { open: true, onOpenChange: (open) => !open && onClose(), children: _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: m.admin_ban_title }), _jsx(AlertDialogDescription, { children: text(m.admin_ban_description, {
|
|
@@ -335,8 +335,8 @@ function BanUserDialog({ labels: m, baseUrl, user, onBanned, onClose, }) {
|
|
|
335
335
|
}, disabled: isPending, children: [isPending ? (_jsx(Loader2, { className: "animate-spin", "data-icon": "inline-start" })) : null, m.admin_action_ban] })] })] }) }));
|
|
336
336
|
}
|
|
337
337
|
function UnbanUserDialog({ labels: m, baseUrl, user, onUnbanned, onClose, }) {
|
|
338
|
-
const [unbanUserAtom] = useState(() => authClientApi(baseUrl).runtime.fn((userId) => Effect.flatMap(authHttpClient(baseUrl), (client) => client.auth.adminUnbanUser({ payload: { userId } })).pipe(Effect.tap(() => Effect.sync(onUnbanned)), Effect.tap(() => Effect.sync(onClose)), Effect.catch((cause) => Effect.sync(() => setError(cause instanceof Error ? cause.message : m.admin_error_unban))))));
|
|
339
338
|
const [error, setError] = useState("");
|
|
339
|
+
const [unbanUserAtom] = useState(() => authClientApi(baseUrl).runtime.fn((userId) => Effect.flatMap(authHttpClient(baseUrl), (client) => client.auth.adminUnbanUser({ payload: { userId } })).pipe(Effect.tap(() => Effect.sync(onUnbanned)), Effect.tap(() => Effect.sync(onClose)), Effect.catch((cause) => Effect.sync(() => setError(cause instanceof Error ? cause.message : m.admin_error_unban))))));
|
|
340
340
|
const unbanUser = useAtomSet(unbanUserAtom);
|
|
341
341
|
const isPending = useAtomValue(unbanUserAtom).waiting;
|
|
342
342
|
return (_jsx(AlertDialog, { open: true, onOpenChange: (open) => !open && onClose(), children: _jsxs(AlertDialogContent, { children: [_jsxs(AlertDialogHeader, { children: [_jsx(AlertDialogTitle, { children: m.admin_unban_title }), _jsx(AlertDialogDescription, { children: text(m.admin_unban_description, {
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import * as Data from "effect/Data";
|
|
2
3
|
import { useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
4
|
import { FormBuilder, FormReact } from "@lucas-barake/effect-form-react";
|
|
4
5
|
import { Effect, Schema } from "effect";
|
|
5
|
-
import {
|
|
6
|
+
import { useState } from "react";
|
|
7
|
+
import { useLatestAtom } from "./hooks.js";
|
|
6
8
|
import { CheckboxField, SubmitButton, SubmitError, TextAreaField, TextField, } from "@krak-stack/registry/effect-form";
|
|
7
9
|
import { parseApiKeyReferrers } from "./api-key.js";
|
|
8
10
|
import { authClientApi, authHttpClient } from "./auth-client-api.js";
|
|
9
11
|
import { ApiKeyPermissions } from "./api-key-permissions.js";
|
|
10
12
|
import { apiKeyReferrers } from "./api-key-referrers.js";
|
|
11
13
|
import { ExtraApiKeyPermissions } from "../extra/schema.js";
|
|
14
|
+
class ApiKeyEditError extends Data.TaggedError("ApiKeyEditError") {
|
|
15
|
+
}
|
|
12
16
|
const editApiKeyFormBuilder = FormBuilder.empty
|
|
13
17
|
.addField("name", Schema.NonEmptyString)
|
|
14
18
|
.addField("enabled", Schema.Boolean)
|
|
@@ -24,16 +28,14 @@ export const ApiKeyEditForm = ({ baseUrl, configId, keyData, messages, permissio
|
|
|
24
28
|
project,
|
|
25
29
|
action,
|
|
26
30
|
})));
|
|
27
|
-
const currentPermissions = Schema.
|
|
31
|
+
const currentPermissions = Schema.decodeOption(ExtraApiKeyPermissions)(keyData.permissions ?? {});
|
|
28
32
|
const currentGrant = currentPermissions._tag === "Some" ? currentPermissions.value : {};
|
|
29
33
|
const initialSelectedPermissions = Object.fromEntries(permissionOptions.map((option) => [
|
|
30
34
|
option.id,
|
|
31
35
|
currentGrant[option.project]?.includes(option.action) ?? false,
|
|
32
36
|
]));
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
permissionOptionsRef.current = permissionOptions;
|
|
36
|
-
permissionsRef.current = permissions;
|
|
37
|
+
const permissionOptionsAtom = useLatestAtom(permissionOptions);
|
|
38
|
+
const permissionsAtom = useLatestAtom(permissions);
|
|
37
39
|
const [form] = useState(() => FormReact.make(editApiKeyFormBuilder, {
|
|
38
40
|
runtime: authClientApi(baseUrl).runtime,
|
|
39
41
|
fields: {
|
|
@@ -43,16 +45,19 @@ export const ApiKeyEditForm = ({ baseUrl, configId, keyData, messages, permissio
|
|
|
43
45
|
permissions: ApiKeyPermissionsField,
|
|
44
46
|
},
|
|
45
47
|
mode: { validation: "onSubmit" },
|
|
46
|
-
onSubmit: (_, { decoded }) => Effect.gen(function* () {
|
|
48
|
+
onSubmit: (_, { decoded, get }) => Effect.gen(function* () {
|
|
47
49
|
const referrers = yield* Effect.try({
|
|
48
50
|
try: () => parseApiKeyReferrers(decoded.referrers, messages.referrersError),
|
|
49
|
-
catch: (cause) =>
|
|
51
|
+
catch: (cause) => new ApiKeyEditError({
|
|
52
|
+
message: cause instanceof Error ? cause.message : messages.updateError,
|
|
53
|
+
cause: cause,
|
|
54
|
+
}),
|
|
50
55
|
});
|
|
51
56
|
const selectedGrant = {};
|
|
52
|
-
for (const project of Object.keys(
|
|
57
|
+
for (const project of Object.keys(get(permissionsAtom))) {
|
|
53
58
|
selectedGrant[project] = [];
|
|
54
59
|
}
|
|
55
|
-
for (const option of
|
|
60
|
+
for (const option of get(permissionOptionsAtom)) {
|
|
56
61
|
if (!decoded.permissions[option.id])
|
|
57
62
|
continue;
|
|
58
63
|
selectedGrant[option.project] = [
|
|
@@ -73,7 +78,10 @@ export const ApiKeyEditForm = ({ baseUrl, configId, keyData, messages, permissio
|
|
|
73
78
|
});
|
|
74
79
|
yield* Effect.sync(onSaved);
|
|
75
80
|
return updated;
|
|
76
|
-
}).pipe(Effect.mapError((cause) =>
|
|
81
|
+
}).pipe(Effect.mapError((cause) => new ApiKeyEditError({
|
|
82
|
+
message: cause instanceof Error ? cause.message : messages.updateError,
|
|
83
|
+
cause: cause,
|
|
84
|
+
}))),
|
|
77
85
|
}));
|
|
78
86
|
const submit = useAtomSet(form.submit);
|
|
79
87
|
const submitResult = useAtomValue(form.submit);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export declare const AssociatedProjectsNotice: ({ baseUrl, getSummary, organizationId, viewLabel, }: {
|
|
1
|
+
export declare const AssociatedProjectsNotice: ({ baseUrl, expanded, getSummary, organizationId, viewLabel, }: {
|
|
2
2
|
baseUrl?: string | undefined;
|
|
3
|
+
expanded?: boolean;
|
|
3
4
|
getSummary: (count: number) => string;
|
|
4
5
|
organizationId?: string | null;
|
|
5
6
|
viewLabel: string;
|
|
@@ -3,6 +3,7 @@ import { useAtomValue } from "@effect/atom-react";
|
|
|
3
3
|
import { AsyncResult, Atom } from "effect/reactivity";
|
|
4
4
|
import { Badge } from "@/components/ui/badge";
|
|
5
5
|
import { authClientApi } from "./auth-client-api.js";
|
|
6
|
+
import { ProjectCardList } from "./project-card-list.js";
|
|
6
7
|
const associatedProjectsAtom = Atom.family((baseUrl) => Atom.family((organizationId) => authClientApi(baseUrl).query("authExtra", "listAssociatedProjects", {
|
|
7
8
|
query: organizationId ? { organizationId } : {},
|
|
8
9
|
timeToLive: "1 minute",
|
|
@@ -11,14 +12,17 @@ const associatedProjectsAtom = Atom.family((baseUrl) => Atom.family((organizatio
|
|
|
11
12
|
organizationId ? `organization:${organizationId}` : "current-user",
|
|
12
13
|
],
|
|
13
14
|
})));
|
|
14
|
-
export const AssociatedProjectsNotice = ({ baseUrl, getSummary, organizationId = null, viewLabel, }) => {
|
|
15
|
+
export const AssociatedProjectsNotice = ({ baseUrl, expanded = false, getSummary, organizationId = null, viewLabel, }) => {
|
|
15
16
|
const result = useAtomValue(associatedProjectsAtom(baseUrl)(organizationId));
|
|
16
17
|
const projects = AsyncResult.match(result, {
|
|
17
18
|
onInitial: () => [],
|
|
18
19
|
onFailure: () => [],
|
|
19
20
|
onSuccess: ({ value }) => Array.from(value),
|
|
20
21
|
});
|
|
21
|
-
if (projects.length
|
|
22
|
+
if (projects.length < (expanded ? 1 : 2))
|
|
22
23
|
return null;
|
|
23
|
-
|
|
24
|
+
if (expanded) {
|
|
25
|
+
return (_jsxs("section", { className: "space-y-2", children: [_jsx("h3", { className: "text-muted-foreground text-xs font-medium", children: getSummary(projects.length) }), _jsx(ProjectCardList, { projects: projects })] }));
|
|
26
|
+
}
|
|
27
|
+
return (_jsx("div", { className: "px-1 py-2", children: _jsxs("details", { className: "border-primary/60 text-muted-foreground border-l-2 pl-3 text-sm", children: [_jsxs("summary", { className: "cursor-pointer list-none [&::-webkit-details-marker]:hidden", children: [getSummary(projects.length), " ", _jsx("span", { className: "text-foreground underline underline-offset-4", children: viewLabel })] }), _jsx("div", { className: "mt-2 flex flex-wrap gap-2", children: projects.map((project) => (_jsx(Badge, { variant: "secondary", children: project.name }, project.id))) })] }) }));
|
|
24
28
|
};
|
|
@@ -29,8 +29,7 @@ const authSessionQueryAtom = Atom.family((baseUrl) => authClientApi(baseUrl)
|
|
|
29
29
|
return unauthorized && !result.waiting
|
|
30
30
|
? AsyncResult.success(null)
|
|
31
31
|
: result;
|
|
32
|
-
}))
|
|
33
|
-
.pipe(refreshOnAuthChange));
|
|
32
|
+
}), refreshOnAuthChange));
|
|
34
33
|
export const authSessionAtom = Atom.family((baseUrl) => Atom.optimistic(authSessionQueryAtom(baseUrl)));
|
|
35
34
|
export const refreshAuthSession = Effect.fn("refreshAuthSession")(function* (registry, baseUrl) {
|
|
36
35
|
const query = authSessionQueryAtom(baseUrl);
|