@coffre/ui 0.1.10 → 0.1.12
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/dist/client/_coffre/assets/account-CyJDFhek.js +2 -0
- package/dist/client/_coffre/assets/account-DHSs5h2f.js +1 -0
- package/dist/client/_coffre/assets/affordances-BQD5B421.js +1 -0
- package/dist/client/_coffre/assets/audit-Bcyp_dU1.js +2 -0
- package/dist/client/_coffre/assets/audit-rMy9mU9Q.js +1 -0
- package/dist/client/_coffre/assets/auth.device-DuvaComb.js +1 -0
- package/dist/client/_coffre/assets/auth.device-yBt_sLZW.js +2 -0
- package/dist/client/_coffre/assets/directory-C4BMGC7-.js +1 -0
- package/dist/client/_coffre/assets/dist-BNkBTkxj.js +1 -0
- package/dist/client/_coffre/assets/globals-BJkzu6T5.css +1 -0
- package/dist/client/_coffre/assets/grants-CyDW25eX.js +1 -0
- package/dist/client/_coffre/assets/icons-BRl8DlXW.js +1 -0
- package/dist/client/_coffre/assets/index-CA1mtrIx.js +12 -0
- package/dist/client/_coffre/assets/link-CqlAJWBd.js +1 -0
- package/dist/client/_coffre/assets/login-B73b6bsJ.js +1 -0
- package/dist/client/_coffre/assets/login-BO1KAGPU.js +2 -0
- package/dist/client/_coffre/assets/offboarding--5vSKNHv.js +1 -0
- package/dist/client/_coffre/assets/page-Dngv8FMr.js +1 -0
- package/dist/client/_coffre/assets/preload-helper-DBha3tys.js +1 -0
- package/dist/client/_coffre/assets/principal-page-C4qDD-d8.js +1 -0
- package/dist/client/_coffre/assets/projects._project._environment-eBKxOZ0_.js +2 -0
- package/dist/client/_coffre/assets/projects._project._environment-or_AX6o5.js +3 -0
- package/dist/client/_coffre/assets/projects._project.index-DHdXfEh-.js +2 -0
- package/dist/client/_coffre/assets/projects._project.index-iynQgenH.js +1 -0
- package/dist/client/_coffre/assets/projects.index-CGW8mRil.js +1 -0
- package/dist/client/_coffre/assets/row-state-BlarvG7E.js +1 -0
- package/dist/client/_coffre/assets/settings-D-7RJIDf.js +1 -0
- package/dist/client/_coffre/assets/suspense-q_eJaZ18.js +1 -0
- package/dist/client/_coffre/assets/tokens._token-0u7midqA.js +2 -0
- package/dist/client/_coffre/assets/tokens._token-C53NqScg.js +1 -0
- package/dist/client/_coffre/assets/tokens.index-DBZTLnbi.js +1 -0
- package/dist/client/_coffre/assets/ui-BPWFJNz7.js +46 -0
- package/dist/client/_coffre/assets/unregistered-CLhgtwUt.js +1 -0
- package/dist/client/_coffre/assets/use-action-LULgF26O.js +1 -0
- package/dist/client/_coffre/assets/use-change-Bd6NZJj9.js +1 -0
- package/dist/client/_coffre/assets/use-shell-Dx92Huhb.js +1 -0
- package/dist/client/_coffre/assets/useQuery-BIIZz1CB.js +1 -0
- package/dist/client/_coffre/assets/useSuspenseQuery-tP9HFZ8w.js +1 -0
- package/dist/client/_coffre/assets/users._user-BXtaL8Ee.js +2 -0
- package/dist/client/_coffre/assets/users._user-CNYVkXaY.js +1 -0
- package/dist/client/_coffre/assets/users.index-Cs9tibIv.js +1 -0
- package/dist/server/.vite/manifest.json +342 -246
- package/dist/server/_coffre/assets/_tanstack-start-manifest_v-T9tMsCwo.js +162 -0
- package/dist/server/_coffre/assets/{account-CUQYGCYh.js → account-BUhhOS5-.js} +150 -117
- package/dist/server/_coffre/assets/{account-DMlUoBxQ.js → account-B_h55GCs.js} +10 -24
- package/dist/server/_coffre/assets/{affordances-BNaXjMOb.js → affordances-CKANXDTG.js} +2 -22
- package/dist/server/_coffre/assets/{async-local-storage-C0cwgkEr.js → async-local-storage-C10uQtMM.js} +3 -2
- package/dist/server/_coffre/assets/{audit-CCdSLmvK.js → audit-B8Ck358-.js} +46 -16
- package/dist/server/_coffre/assets/audit-DFsXfeAQ.js +31 -0
- package/dist/server/_coffre/assets/{auth.device-BoFM1jcf.js → auth.device-BXf_JjT7.js} +5 -5
- package/dist/server/_coffre/assets/{auth.device-C05u5ROO.js → auth.device-cqjWACvB.js} +7 -5
- package/dist/server/_coffre/assets/{directory-GsnYkse0.js → directory-C9SfNgpM.js} +87 -112
- package/dist/server/_coffre/assets/{use-action-DwEmf58L.js → dist-CnnV3t2g.js} +3 -48
- package/dist/server/_coffre/assets/globals-BJkzu6T5.css +1 -0
- package/dist/server/_coffre/assets/grants--315KmXu.js +158 -0
- package/dist/server/_coffre/assets/{page-BdnhpwvH.js → icons-CWsTEfpn.js} +125 -436
- package/dist/server/_coffre/assets/lazyRouteComponent-CqBNCGuZ.js +480 -0
- package/dist/server/_coffre/assets/link-42ZWdjzZ.js +422 -0
- package/dist/server/_coffre/assets/{login-DUtCQju5.js → login-CQSkYW_D.js} +7 -5
- package/dist/server/_coffre/assets/{login-B2njIq_o.js → login-LBpXXfsQ.js} +2 -2
- package/dist/server/_coffre/assets/matchContext-qLfYbC6_.js +56 -0
- package/dist/server/_coffre/assets/{offboarding-8yMa7ViM.js → offboarding-CykelNis.js} +11 -79
- package/dist/server/_coffre/assets/page-BGeDoQO5.js +3531 -0
- package/dist/server/_coffre/assets/{principal-page-B8zPcS2b.js → principal-page-CRdoAQOq.js} +51 -42
- package/dist/server/_coffre/assets/{projects._project._environment-DdIOc7wx.js → projects._project._environment-BXU1Mee5.js} +4 -11
- package/dist/server/_coffre/assets/{projects._project._environment-BZ5Z80V8.js → projects._project._environment-BrDqn8kW.js} +129 -748
- package/dist/server/_coffre/assets/{projects._project.index-CuEAUwGn.js → projects._project.index-CAxBU4tY.js} +134 -96
- package/dist/server/_coffre/assets/{projects._project.index-DvbcU1kh.js → projects._project.index-CYyUVTCl.js} +5 -4
- package/dist/server/_coffre/assets/{projects.index-5HI0wOuG.js → projects.index-D6ZoDE_0.js} +57 -55
- package/dist/server/_coffre/assets/{react-dom-qCTiwGGR.js → react-dom-bBoJXlK2.js} +417 -51
- package/dist/server/_coffre/assets/{router-CQDoql8s.js → router-Bu2qtyqw.js} +376 -92
- package/dist/server/_coffre/assets/row-state-CAItu3n_.js +117 -0
- package/dist/server/_coffre/assets/{settings-BVz78wjP.js → settings-ByeF6hBa.js} +8 -6
- package/dist/server/_coffre/assets/suspense-beD01bb8.js +602 -0
- package/dist/server/_coffre/assets/tokens._token-CM01QPCq.js +10 -0
- package/dist/server/_coffre/assets/{tokens._token-CWs3Mtki.js → tokens._token-D2E4P3Qc.js} +97 -79
- package/dist/server/_coffre/assets/{tokens.index-Ck0LN7aC.js → tokens.index-Cmrgn3mU.js} +9 -6
- package/dist/server/_coffre/assets/{ui-D_slKpSF.js → ui-DvlGkmaH.js} +7 -836
- package/dist/server/_coffre/assets/{unregistered-Z17da4Rc.js → unregistered-DSArejP9.js} +5 -3
- package/dist/server/_coffre/assets/use-action-C2wz34kq.js +47 -0
- package/dist/server/_coffre/assets/use-change-CJpGSNIq.js +1212 -0
- package/dist/server/_coffre/assets/use-shell-C3iYcyP1.js +462 -0
- package/dist/server/_coffre/assets/useQuery-ChxaQ4Cb.js +8 -0
- package/dist/server/_coffre/assets/{useStore-DWGPqzXR.js → useRouter-CaUSUNsw.js} +1 -420
- package/dist/server/_coffre/assets/useSuspenseQuery-BjAmlGZl.js +117 -0
- package/dist/server/_coffre/assets/users._user-BVeR9fZP.js +10 -0
- package/dist/server/_coffre/assets/{users._user-CMwj-VI9.js → users._user-Cih2Etf4.js} +4 -5
- package/dist/server/_coffre/assets/{users.index-fWHv6A30.js → users.index-Bo2_a95G.js} +9 -6
- package/dist/server/index.js +6 -5
- package/package.json +5 -3
- package/src/components/directory.tsx +75 -104
- package/src/components/grants.tsx +60 -112
- package/src/components/icons.tsx +0 -34
- package/src/components/offboarding.tsx +1 -52
- package/src/components/principal-page.tsx +54 -67
- package/src/components/principal-picker.tsx +7 -16
- package/src/components/row-state.tsx +95 -0
- package/src/components/service-tokens.tsx +75 -64
- package/src/components/shell.tsx +1 -1
- package/src/lib/announce.ts +36 -0
- package/src/lib/changes.ts +498 -0
- package/src/lib/coffre.ts +1 -1
- package/src/lib/optimistic.ts +233 -0
- package/src/lib/queries.ts +385 -0
- package/src/lib/use-action.ts +20 -15
- package/src/lib/use-change.ts +42 -0
- package/src/lib/use-shell.ts +17 -0
- package/src/router.tsx +17 -9
- package/src/routes/__root.tsx +8 -38
- package/src/routes/account.tsx +163 -154
- package/src/routes/audit.tsx +51 -72
- package/src/routes/auth.device.tsx +4 -2
- package/src/routes/login.tsx +3 -2
- package/src/routes/projects.$project.$environment.tsx +223 -238
- package/src/routes/projects.$project.index.tsx +136 -118
- package/src/routes/projects.index.tsx +117 -145
- package/src/routes/settings.tsx +7 -7
- package/src/routes/tokens.$token.tsx +14 -17
- package/src/routes/tokens.index.tsx +8 -4
- package/src/routes/unregistered.tsx +3 -2
- package/src/routes/users.$user.tsx +4 -4
- package/src/routes/users.index.tsx +8 -4
- package/src/shared/models.ts +1 -5
- package/src/styles/globals.css +80 -50
- package/dist/client/_coffre/assets/account-B48wuSF8.js +0 -1
- package/dist/client/_coffre/assets/account-BkNyIDT7.js +0 -2
- package/dist/client/_coffre/assets/affordances-CmoY-8Xf.js +0 -1
- package/dist/client/_coffre/assets/audit-BvwKYb-5.js +0 -2
- package/dist/client/_coffre/assets/audit-D02H-zxS.js +0 -1
- package/dist/client/_coffre/assets/auth.device-BP5FY0K1.js +0 -1
- package/dist/client/_coffre/assets/auth.device-DYOONgFF.js +0 -2
- package/dist/client/_coffre/assets/coffre-BBp7cKVa.js +0 -1
- package/dist/client/_coffre/assets/directory-Bu0EIxqI.js +0 -1
- package/dist/client/_coffre/assets/globals-Bh2x1gBM.css +0 -1
- package/dist/client/_coffre/assets/grants-DavcwofW.js +0 -1
- package/dist/client/_coffre/assets/index-CDPlq5rM.js +0 -12
- package/dist/client/_coffre/assets/login-C-wTm_t1.js +0 -2
- package/dist/client/_coffre/assets/login-CLLv1om9.js +0 -1
- package/dist/client/_coffre/assets/offboarding-DWsE2FSa.js +0 -1
- package/dist/client/_coffre/assets/page-DbSS7pYH.js +0 -1
- package/dist/client/_coffre/assets/preload-helper-DduCCcmc.js +0 -46
- package/dist/client/_coffre/assets/principal-page-Bp_iwuSd.js +0 -1
- package/dist/client/_coffre/assets/projects._project._environment-BMeX_B8l.js +0 -2
- package/dist/client/_coffre/assets/projects._project._environment-CT0A-hIU.js +0 -3
- package/dist/client/_coffre/assets/projects._project.index-C_xYOGLT.js +0 -2
- package/dist/client/_coffre/assets/projects._project.index-Chcf-cUd.js +0 -1
- package/dist/client/_coffre/assets/projects.index-CfOtb1X5.js +0 -2
- package/dist/client/_coffre/assets/projects.index-DSjOhLDh.js +0 -1
- package/dist/client/_coffre/assets/settings-BC9cUJNK.js +0 -1
- package/dist/client/_coffre/assets/settings-Bkj_E21y.js +0 -2
- package/dist/client/_coffre/assets/tokens._token-BA0KqvaW.js +0 -1
- package/dist/client/_coffre/assets/tokens._token-Dh9jLOkm.js +0 -2
- package/dist/client/_coffre/assets/tokens.index-BgAMWkHT.js +0 -2
- package/dist/client/_coffre/assets/tokens.index-CHueIAv1.js +0 -1
- package/dist/client/_coffre/assets/unregistered-D5go1AfR.js +0 -1
- package/dist/client/_coffre/assets/use-action-l__xZDYY.js +0 -1
- package/dist/client/_coffre/assets/users._user-Dwqa0gv5.js +0 -1
- package/dist/client/_coffre/assets/users._user-xJAb3T6Y.js +0 -2
- package/dist/client/_coffre/assets/users.index-BJoF-L37.js +0 -2
- package/dist/client/_coffre/assets/users.index-YUjtbTGy.js +0 -1
- package/dist/server/_coffre/assets/_tanstack-start-manifest_v-BKg2AlPu.js +0 -133
- package/dist/server/_coffre/assets/audit-CThXn2v7.js +0 -74
- package/dist/server/_coffre/assets/coffre-C2ANsTAz.js +0 -281
- package/dist/server/_coffre/assets/globals-Bh2x1gBM.css +0 -1
- package/dist/server/_coffre/assets/grants-B6k4Fu9z.js +0 -243
- package/dist/server/_coffre/assets/projects.index-uiomWX_l.js +0 -54
- package/dist/server/_coffre/assets/settings-4oRyDizv.js +0 -18
- package/dist/server/_coffre/assets/tokens._token-CF_deAwq.js +0 -18
- package/dist/server/_coffre/assets/tokens.index-DF_07KEe.js +0 -10
- package/dist/server/_coffre/assets/users._user-DUzwkSKT.js +0 -10
- package/dist/server/_coffre/assets/users.index-BbuweTwH.js +0 -10
- package/src/components/syncs.tsx +0 -581
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useMutation, useMutationState, useQueryClient, type QueryKey } from '@tanstack/react-query';
|
|
2
|
+
import { useCallback } from 'react';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
changeKey,
|
|
6
|
+
changeOptions,
|
|
7
|
+
dismiss,
|
|
8
|
+
failedAdds,
|
|
9
|
+
itemStatus,
|
|
10
|
+
type Change,
|
|
11
|
+
type ChangeContext,
|
|
12
|
+
} from './optimistic';
|
|
13
|
+
|
|
14
|
+
/** Make a change that shows before the server answers (`lib/optimistic.ts`). */
|
|
15
|
+
export function useChange<TData, TItem, TVars, TResult>(change: Change<TData, TItem, TVars, TResult>) {
|
|
16
|
+
const queryClient = useQueryClient();
|
|
17
|
+
return useMutation(changeOptions(queryClient, change)).mutate;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/** How each item of a list stands, from the changes made to it here. */
|
|
21
|
+
export function useChangeStatus(list: QueryKey) {
|
|
22
|
+
const queryClient = useQueryClient();
|
|
23
|
+
const changes = useMutationState({
|
|
24
|
+
filters: { mutationKey: changeKey(list) },
|
|
25
|
+
select: (mutation) => ({
|
|
26
|
+
mutationId: mutation.mutationId,
|
|
27
|
+
state: mutation.state as typeof mutation.state & { context: ChangeContext | undefined },
|
|
28
|
+
}),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const status = useCallback((id: string) => itemStatus(changes, id), [changes]);
|
|
32
|
+
|
|
33
|
+
/** Adds the server refused, whose items are not in `present`: rendered as rows of their own. */
|
|
34
|
+
const refusedAdds = useCallback(
|
|
35
|
+
<TVars,>(present: readonly string[]) => failedAdds<TVars>(changes, present),
|
|
36
|
+
[changes],
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const forget = useCallback((mutationId: number) => dismiss(queryClient, mutationId), [queryClient]);
|
|
40
|
+
|
|
41
|
+
return { status, failedAdds: refusedAdds, dismiss: forget };
|
|
42
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useSuspenseQueries } from '@tanstack/react-query';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
|
|
4
|
+
import { useCoffre } from './coffre';
|
|
5
|
+
import { queries, shellOf, type Shell } from './queries';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The shell as a component reads it: from the same queries the root loader
|
|
9
|
+
* fetched, so it follows any change that refetches them.
|
|
10
|
+
*/
|
|
11
|
+
export function useShell(): Shell {
|
|
12
|
+
const client = useCoffre();
|
|
13
|
+
const [auth, me, projects] = useSuspenseQueries({
|
|
14
|
+
queries: [queries.auth(client), queries.me(client), queries.projects(client)],
|
|
15
|
+
});
|
|
16
|
+
return useMemo(() => shellOf(auth.data, me.data, projects.data), [auth.data, me.data, projects.data]);
|
|
17
|
+
}
|
package/src/router.tsx
CHANGED
|
@@ -1,30 +1,38 @@
|
|
|
1
1
|
import { createClient, type CoffreClient } from '@coffre/client';
|
|
2
|
+
import type { QueryClient } from '@tanstack/react-query';
|
|
2
3
|
import { createRouter as createTanStackRouter } from '@tanstack/react-router';
|
|
4
|
+
import { setupRouterSsrQueryIntegration } from '@tanstack/react-router-ssr-query';
|
|
3
5
|
import { getGlobalStartContext } from '@tanstack/react-start';
|
|
4
6
|
import { routeTree } from './routeTree.gen';
|
|
5
7
|
import { NotFound, RouteError } from './components/route-states';
|
|
8
|
+
import { createQueryClient } from './lib/queries';
|
|
6
9
|
|
|
7
10
|
/**
|
|
8
11
|
* The router factory. TanStack Start calls this once per request on the server
|
|
9
|
-
* and once on the client
|
|
12
|
+
* and once on the client, so each gets a query cache of its own: a request's
|
|
13
|
+
* reads are never another visitor's. The server's reads travel with the page,
|
|
14
|
+
* so the browser starts from them rather than asking again.
|
|
10
15
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* which is the behaviour the Next.js version got from `force-dynamic`.
|
|
16
|
+
* Loaders read through the query cache (`lib/queries.ts`, which says how
|
|
17
|
+
* fresh it keeps a page), so the router keeps no copy of its own: it runs a
|
|
18
|
+
* route's loader on every navigation and every hover, and the cache answers
|
|
19
|
+
* whatever it already holds. A hover is then a read the click reuses.
|
|
16
20
|
*/
|
|
17
21
|
export function getRouter() {
|
|
18
|
-
|
|
22
|
+
const queryClient = createQueryClient();
|
|
23
|
+
const router = createTanStackRouter({
|
|
19
24
|
routeTree,
|
|
20
25
|
defaultPreload: 'intent',
|
|
21
26
|
defaultStaleTime: 0,
|
|
27
|
+
defaultPreloadStaleTime: 0,
|
|
22
28
|
scrollRestoration: true,
|
|
23
29
|
defaultNotFoundComponent: NotFound,
|
|
24
30
|
defaultErrorComponent: RouteError,
|
|
25
31
|
ssr: { nonce: cspNonce() },
|
|
26
|
-
context: { client: requestClient() },
|
|
32
|
+
context: { client: requestClient(), queryClient },
|
|
27
33
|
});
|
|
34
|
+
setupRouterSsrQueryIntegration({ router, queryClient });
|
|
35
|
+
return router;
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
/**
|
|
@@ -66,7 +74,7 @@ function cspNonce(): string | undefined {
|
|
|
66
74
|
type RequestContext = { cspNonce: string; client: CoffreClient };
|
|
67
75
|
|
|
68
76
|
/** What every loader and component can reach through the router. */
|
|
69
|
-
export type RouterContext = { client: CoffreClient };
|
|
77
|
+
export type RouterContext = { client: CoffreClient; queryClient: QueryClient };
|
|
70
78
|
|
|
71
79
|
// Start's server entry reads this `Register`, and its context helpers the
|
|
72
80
|
// one below: the two do not merge, so each hears of the request context.
|
package/src/routes/__root.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { CoffreError, type CoffreClient } from '@coffre/client';
|
|
2
1
|
import type { ReactNode } from 'react';
|
|
3
2
|
import {
|
|
4
3
|
createRootRouteWithContext,
|
|
@@ -11,13 +10,14 @@ import {
|
|
|
11
10
|
} from '@tanstack/react-router';
|
|
12
11
|
import { Toaster } from 'sonner';
|
|
13
12
|
import globalsCss from '../styles/globals.css?url';
|
|
14
|
-
import {
|
|
13
|
+
import { loadShell } from '../lib/queries';
|
|
14
|
+
import { useShell } from '../lib/use-shell';
|
|
15
15
|
import type { RouterContext } from '../router';
|
|
16
|
-
import type { Me } from '../shared/models';
|
|
17
16
|
import { Brand, Shell, sidebarBootScript } from '../components/shell';
|
|
18
17
|
import { TooltipProvider } from '../components/ui';
|
|
19
18
|
import { ThemeToggle, themeBootScript } from '../components/theme';
|
|
20
19
|
import { Agentation } from '../components/agentation';
|
|
20
|
+
import { LiveRegion } from '../components/row-state';
|
|
21
21
|
import { markSvg } from '../components/mark';
|
|
22
22
|
import faviconPng from '../assets/favicon-32.png?url';
|
|
23
23
|
import appleTouchIcon from '../assets/apple-touch-icon.png?url';
|
|
@@ -43,8 +43,8 @@ export const Route = createRootRouteWithContext<RouterContext>()({
|
|
|
43
43
|
}),
|
|
44
44
|
|
|
45
45
|
// Identity and the project tree, which the shell needs on every screen.
|
|
46
|
-
loader: async ({ context: { client }, location }) => {
|
|
47
|
-
const shell = await loadShell(client);
|
|
46
|
+
loader: async ({ context: { client, queryClient }, location }) => {
|
|
47
|
+
const shell = await loadShell(queryClient, client);
|
|
48
48
|
|
|
49
49
|
if (shell.registrationRequired && location.pathname !== '/unregistered') {
|
|
50
50
|
throw redirect({ to: '/unregistered' });
|
|
@@ -70,44 +70,12 @@ export const Route = createRootRouteWithContext<RouterContext>()({
|
|
|
70
70
|
) {
|
|
71
71
|
throw redirect({ to: '/projects' });
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
return shell;
|
|
75
73
|
},
|
|
76
74
|
|
|
77
75
|
shellComponent: RootDocument,
|
|
78
76
|
component: RootComponent,
|
|
79
77
|
});
|
|
80
78
|
|
|
81
|
-
/**
|
|
82
|
-
* Who is looking, how this instance signs people in, and the projects they
|
|
83
|
-
* can see. Three calls at once: for someone signed out or not yet a member,
|
|
84
|
-
* the project list is refused, and they get the sign-in or closed-door page.
|
|
85
|
-
*/
|
|
86
|
-
async function loadShell(client: CoffreClient) {
|
|
87
|
-
const [auth, me, projects] = await Promise.all([
|
|
88
|
-
client.auth(),
|
|
89
|
-
client.me().catch((error: unknown) => {
|
|
90
|
-
if (error instanceof CoffreError && error.status === 401) return null;
|
|
91
|
-
throw error;
|
|
92
|
-
}),
|
|
93
|
-
client.projects.list().then(
|
|
94
|
-
({ projects }) => projects,
|
|
95
|
-
() => [],
|
|
96
|
-
),
|
|
97
|
-
]);
|
|
98
|
-
const member: Me | null = me?.registered === true ? me : null;
|
|
99
|
-
return {
|
|
100
|
-
auth,
|
|
101
|
-
principal: me === null ? null : me.principal,
|
|
102
|
-
instanceRole: member?.instanceRole ?? null,
|
|
103
|
-
projects,
|
|
104
|
-
capabilities: deriveUiCapabilities(member, projects),
|
|
105
|
-
registrationRequired: me !== null && !me.registered,
|
|
106
|
-
/** A member the vault refuses: their record failed its integrity check. */
|
|
107
|
-
accessTampered: me?.tampered === true,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
79
|
function RootDocument({ children }: { children: ReactNode }) {
|
|
112
80
|
return (
|
|
113
81
|
<html lang="en" suppressHydrationWarning>
|
|
@@ -150,7 +118,7 @@ function Toasts() {
|
|
|
150
118
|
}
|
|
151
119
|
|
|
152
120
|
function RootComponent() {
|
|
153
|
-
const { principal, instanceRole, projects, capabilities } =
|
|
121
|
+
const { principal, instanceRole, projects, capabilities } = useShell();
|
|
154
122
|
const pathname = useRouterState({ select: (state) => state.location.pathname });
|
|
155
123
|
|
|
156
124
|
// Sign-in gets no navigation. Every destination in the sidebar and the
|
|
@@ -171,6 +139,7 @@ function RootComponent() {
|
|
|
171
139
|
</main>
|
|
172
140
|
</div>
|
|
173
141
|
<Toasts />
|
|
142
|
+
<LiveRegion />
|
|
174
143
|
<Agentation />
|
|
175
144
|
</TooltipProvider>
|
|
176
145
|
);
|
|
@@ -192,6 +161,7 @@ function RootComponent() {
|
|
|
192
161
|
</Shell>
|
|
193
162
|
|
|
194
163
|
<Toasts />
|
|
164
|
+
<LiveRegion />
|
|
195
165
|
<Agentation />
|
|
196
166
|
</TooltipProvider>
|
|
197
167
|
);
|
package/src/routes/account.tsx
CHANGED
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
import type { IdentityRow, SessionRow } from '@coffre/client';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { useSuspenseQueries } from '@tanstack/react-query';
|
|
3
|
+
import { createFileRoute } from '@tanstack/react-router';
|
|
4
|
+
import { Fragment } from 'react';
|
|
5
|
+
import { useShell } from '../lib/use-shell';
|
|
4
6
|
import { Card, Fact, PageHeader } from '../components/page';
|
|
5
7
|
import { ThemeCards } from '../components/theme';
|
|
6
8
|
import { InstanceRole } from '../components/directory';
|
|
7
9
|
import { ConfirmButton, EmptyState, ErrorLine, Notice, Timestamp } from '../components/ui';
|
|
8
10
|
import { Monitor, ProviderMark, SignOut, Terminal, X } from '../components/icons';
|
|
9
11
|
import { signinErrorMessage } from '../lib/signin-errors';
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
+
import { useCoffre } from '../lib/coffre';
|
|
13
|
+
import { endSession, unlinkIdentity } from '../lib/changes';
|
|
14
|
+
import { loadShell, queries } from '../lib/queries';
|
|
15
|
+
import { useChange, useChangeStatus } from '../lib/use-change';
|
|
16
|
+
import { RowFailure, RowPending, rowClass } from '../components/row-state';
|
|
12
17
|
|
|
13
18
|
type Search = { linked?: string; error?: string };
|
|
14
19
|
|
|
@@ -27,32 +32,21 @@ export const Route = createFileRoute('/account')({
|
|
|
27
32
|
}
|
|
28
33
|
return out;
|
|
29
34
|
},
|
|
30
|
-
// The sign-in half: which accounts you sign in with
|
|
31
|
-
// in
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
providers: [] as { id: string; label: string; brand: string }[],
|
|
40
|
-
identities: [] as IdentityRow[],
|
|
41
|
-
sessions: [] as SessionRow[],
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
const { providers } = auth.signin;
|
|
45
|
-
return uiResult(async () => {
|
|
46
|
-
const [{ identities }, { sessions }] = await Promise.all([client.identities.list(), client.sessions.list()]);
|
|
47
|
-
return { signin: true, providers, identities, sessions };
|
|
48
|
-
});
|
|
35
|
+
// The sign-in half: which accounts you sign in with and where you are
|
|
36
|
+
// signed in. Absent behind Cloudflare Access, which owns sessions there.
|
|
37
|
+
loader: async ({ context: { client, queryClient } }) => {
|
|
38
|
+
const shell = await loadShell(queryClient, client);
|
|
39
|
+
if (shell.auth.signin === null || shell.principal?.type !== 'user') return;
|
|
40
|
+
await Promise.all([
|
|
41
|
+
queryClient.fetchQuery(queries.identities(client)),
|
|
42
|
+
queryClient.fetchQuery(queries.sessions(client)),
|
|
43
|
+
]);
|
|
49
44
|
},
|
|
50
45
|
component: AccountPage,
|
|
51
46
|
});
|
|
52
47
|
|
|
53
48
|
function AccountPage() {
|
|
54
|
-
const { principal, instanceRole } =
|
|
55
|
-
const signin = Route.useLoaderData();
|
|
49
|
+
const { principal, instanceRole, auth } = useShell();
|
|
56
50
|
|
|
57
51
|
return (
|
|
58
52
|
<>
|
|
@@ -87,21 +81,29 @@ function AccountPage() {
|
|
|
87
81
|
</Card>
|
|
88
82
|
)}
|
|
89
83
|
|
|
90
|
-
{
|
|
91
|
-
<
|
|
92
|
-
) : (
|
|
93
|
-
signin.signin &&
|
|
94
|
-
principal?.type === 'user' && (
|
|
95
|
-
<>
|
|
96
|
-
<SigninAccounts email={principal.id} {...signin} />
|
|
97
|
-
<Sessions sessions={signin.sessions} providers={signin.providers} />
|
|
98
|
-
</>
|
|
99
|
-
)
|
|
84
|
+
{auth.signin !== null && principal?.type === 'user' && (
|
|
85
|
+
<SignIn email={principal.id} providers={auth.signin.providers} />
|
|
100
86
|
)}
|
|
101
87
|
</>
|
|
102
88
|
);
|
|
103
89
|
}
|
|
104
90
|
|
|
91
|
+
/** Which accounts you sign in with, and where you are signed in. */
|
|
92
|
+
function SignIn({ email, providers }: { email: string; providers: Provider[] }) {
|
|
93
|
+
const client = useCoffre();
|
|
94
|
+
const [{ data: identities }, { data: sessions }] = useSuspenseQueries({
|
|
95
|
+
queries: [queries.identities(client), queries.sessions(client)],
|
|
96
|
+
});
|
|
97
|
+
if (!identities.ok) return <ErrorLine error={identities.error} />;
|
|
98
|
+
if (!sessions.ok) return <ErrorLine error={sessions.error} />;
|
|
99
|
+
return (
|
|
100
|
+
<>
|
|
101
|
+
<SigninAccounts email={email} providers={providers} identities={identities.identities} />
|
|
102
|
+
<Sessions sessions={sessions.sessions} providers={providers} />
|
|
103
|
+
</>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
|
|
105
107
|
/**
|
|
106
108
|
* Sign-out is a form post: a GET could be triggered by any image tag on any
|
|
107
109
|
* page, and the server's origin check covers form posts.
|
|
@@ -134,8 +136,9 @@ function SigninAccounts({
|
|
|
134
136
|
}) {
|
|
135
137
|
const { linked, error } = Route.useSearch();
|
|
136
138
|
const message = signinErrorMessage(error);
|
|
137
|
-
const
|
|
138
|
-
const
|
|
139
|
+
const change = unlinkIdentity(useCoffre());
|
|
140
|
+
const unlink = useChange(change);
|
|
141
|
+
const { status, dismiss } = useChangeStatus(change.list.queryKey);
|
|
139
142
|
|
|
140
143
|
return (
|
|
141
144
|
<Card
|
|
@@ -143,12 +146,12 @@ function SigninAccounts({
|
|
|
143
146
|
title="Sign-in accounts"
|
|
144
147
|
description="coffre recognises you by these accounts, never by an email address alone. A new account is linked here, while you are signed in."
|
|
145
148
|
>
|
|
146
|
-
{(linked !== undefined || message !== null
|
|
149
|
+
{(linked !== undefined || message !== null) && (
|
|
147
150
|
<div className="card-body">
|
|
148
151
|
{linked !== undefined && (
|
|
149
152
|
<Notice tone="good">{providerLabel(providers, linked)} account linked.</Notice>
|
|
150
153
|
)}
|
|
151
|
-
<ErrorLine error={message
|
|
154
|
+
<ErrorLine error={message} />
|
|
152
155
|
</div>
|
|
153
156
|
)}
|
|
154
157
|
|
|
@@ -174,61 +177,68 @@ function SigninAccounts({
|
|
|
174
177
|
{identities.map((identity) => {
|
|
175
178
|
const label = providerLabel(providers, identity.provider);
|
|
176
179
|
const brand = providers.find((p) => p.id === identity.provider)?.brand ?? 'oidc';
|
|
180
|
+
const state = status(identity.id);
|
|
177
181
|
return (
|
|
178
|
-
<
|
|
179
|
-
<
|
|
180
|
-
<
|
|
181
|
-
<
|
|
182
|
-
|
|
183
|
-
<span>
|
|
184
|
-
|
|
182
|
+
<Fragment key={identity.id}>
|
|
183
|
+
<tr className={rowClass(state)}>
|
|
184
|
+
<td>
|
|
185
|
+
<span className="cell-account">
|
|
186
|
+
<ProviderMark brand={brand} />
|
|
187
|
+
<span className="cell-stack">
|
|
188
|
+
<span>{label}</span>
|
|
189
|
+
{identity.email !== null && <small className="mono">{identity.email}</small>}
|
|
190
|
+
</span>
|
|
185
191
|
</span>
|
|
186
|
-
</
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
<
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
() =>
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
192
|
+
</td>
|
|
193
|
+
<td className="nowrap">
|
|
194
|
+
<Timestamp iso={identity.createdAt} />
|
|
195
|
+
</td>
|
|
196
|
+
<td className="nowrap cell-muted">
|
|
197
|
+
{identity.lastSignInAt === null ? (
|
|
198
|
+
'Never'
|
|
199
|
+
) : (
|
|
200
|
+
<Timestamp iso={identity.lastSignInAt} display="relative" />
|
|
201
|
+
)}
|
|
202
|
+
</td>
|
|
203
|
+
<td className="col-actions">
|
|
204
|
+
{state.state === 'pending' ? (
|
|
205
|
+
<RowPending status={state} />
|
|
206
|
+
) : (
|
|
207
|
+
<ConfirmButton
|
|
208
|
+
trigger={
|
|
209
|
+
<button className="act">
|
|
210
|
+
<X size={13} />
|
|
211
|
+
Unlink
|
|
212
|
+
</button>
|
|
213
|
+
}
|
|
214
|
+
title={`Unlink this ${label} account?`}
|
|
215
|
+
body={
|
|
216
|
+
identities.length === 1 ? (
|
|
217
|
+
<>
|
|
218
|
+
It stops signing you in, and every session it opened ends now,
|
|
219
|
+
this one included if you signed in with it. Your next sign-in
|
|
220
|
+
with any account whose verified email is{' '}
|
|
221
|
+
<span className="mono">{email}</span> links that account instead.
|
|
222
|
+
</>
|
|
223
|
+
) : (
|
|
224
|
+
<>
|
|
225
|
+
It stops signing you in, and every session it opened ends now,
|
|
226
|
+
this one included if you signed in with it.
|
|
227
|
+
</>
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
confirmLabel="Unlink"
|
|
231
|
+
onConfirm={() => unlink({ ...identity, label })}
|
|
232
|
+
/>
|
|
233
|
+
)}
|
|
234
|
+
</td>
|
|
235
|
+
</tr>
|
|
236
|
+
<RowFailure
|
|
237
|
+
status={state}
|
|
238
|
+
columns={4}
|
|
239
|
+
onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
|
|
240
|
+
/>
|
|
241
|
+
</Fragment>
|
|
232
242
|
);
|
|
233
243
|
})}
|
|
234
244
|
</tbody>
|
|
@@ -264,8 +274,9 @@ function Sessions({
|
|
|
264
274
|
sessions: SessionRow[];
|
|
265
275
|
providers: Provider[];
|
|
266
276
|
}) {
|
|
267
|
-
const
|
|
268
|
-
const
|
|
277
|
+
const change = endSession(useCoffre());
|
|
278
|
+
const end = useChange(change);
|
|
279
|
+
const { status, dismiss } = useChangeStatus(change.list.queryKey);
|
|
269
280
|
|
|
270
281
|
return (
|
|
271
282
|
<Card
|
|
@@ -273,11 +284,6 @@ function Sessions({
|
|
|
273
284
|
title="Sessions"
|
|
274
285
|
description="Browsers and command lines signed in as you. Ending one signs it out at its next request."
|
|
275
286
|
>
|
|
276
|
-
{error !== null && (
|
|
277
|
-
<div className="card-body">
|
|
278
|
-
<ErrorLine error={error} />
|
|
279
|
-
</div>
|
|
280
|
-
)}
|
|
281
287
|
{sessions.length === 0 ? (
|
|
282
288
|
<EmptyState title="No sessions">Nothing is signed in as you right now.</EmptyState>
|
|
283
289
|
) : (
|
|
@@ -294,62 +300,65 @@ function Sessions({
|
|
|
294
300
|
</tr>
|
|
295
301
|
</thead>
|
|
296
302
|
<tbody>
|
|
297
|
-
{sessions.map((session) =>
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
<
|
|
303
|
-
<span>
|
|
304
|
-
{session.
|
|
305
|
-
|
|
303
|
+
{sessions.map((session) => {
|
|
304
|
+
const state = status(session.id);
|
|
305
|
+
return (
|
|
306
|
+
<Fragment key={session.id}>
|
|
307
|
+
<tr className={rowClass(state)}>
|
|
308
|
+
<td>
|
|
309
|
+
<span className="cell-account">
|
|
310
|
+
{session.kind === 'cli' ? <Terminal size={15} /> : <Monitor size={15} />}
|
|
311
|
+
<span className="cell-stack">
|
|
312
|
+
<span>
|
|
313
|
+
{session.label ?? (session.kind === 'cli' ? 'Command line' : 'Browser')}{' '}
|
|
314
|
+
{session.current && <span className="tag tag-blue">this browser</span>}
|
|
315
|
+
</span>
|
|
316
|
+
<small>
|
|
317
|
+
{session.kind === 'cli'
|
|
318
|
+
? 'coffre login'
|
|
319
|
+
: `via ${providerLabel(providers, session.provider)}`}
|
|
320
|
+
{session.lastUsedIp !== null && (
|
|
321
|
+
<>
|
|
322
|
+
{' · '}
|
|
323
|
+
<span className="mono">{session.lastUsedIp}</span>
|
|
324
|
+
</>
|
|
325
|
+
)}
|
|
326
|
+
</small>
|
|
327
|
+
</span>
|
|
306
328
|
</span>
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
run(
|
|
341
|
-
() => coffre.sessions.revoke(session.id),
|
|
342
|
-
() => toast.success('Session ended'),
|
|
343
|
-
)
|
|
344
|
-
}
|
|
345
|
-
>
|
|
346
|
-
<X size={13} />
|
|
347
|
-
End
|
|
348
|
-
</button>
|
|
349
|
-
)}
|
|
350
|
-
</td>
|
|
351
|
-
</tr>
|
|
352
|
-
))}
|
|
329
|
+
</td>
|
|
330
|
+
<td className="nowrap cell-muted">
|
|
331
|
+
<Timestamp iso={session.lastUsedAt ?? session.createdAt} display="relative" />
|
|
332
|
+
</td>
|
|
333
|
+
<td className="nowrap cell-muted">
|
|
334
|
+
<Timestamp iso={session.expiresAt} display="relative" />
|
|
335
|
+
</td>
|
|
336
|
+
<td className="col-actions">
|
|
337
|
+
{session.current ? (
|
|
338
|
+
<form method="post" action="/auth/signout">
|
|
339
|
+
<button className="act" type="submit">
|
|
340
|
+
<SignOut size={13} />
|
|
341
|
+
Sign out
|
|
342
|
+
</button>
|
|
343
|
+
</form>
|
|
344
|
+
) : state.state === 'pending' ? (
|
|
345
|
+
<RowPending status={state} />
|
|
346
|
+
) : (
|
|
347
|
+
<button className="act" onClick={() => end(session)}>
|
|
348
|
+
<X size={13} />
|
|
349
|
+
End
|
|
350
|
+
</button>
|
|
351
|
+
)}
|
|
352
|
+
</td>
|
|
353
|
+
</tr>
|
|
354
|
+
<RowFailure
|
|
355
|
+
status={state}
|
|
356
|
+
columns={4}
|
|
357
|
+
onDismiss={() => state.state === 'failed' && dismiss(state.mutationId)}
|
|
358
|
+
/>
|
|
359
|
+
</Fragment>
|
|
360
|
+
);
|
|
361
|
+
})}
|
|
353
362
|
</tbody>
|
|
354
363
|
</table>
|
|
355
364
|
</div>
|