create-signet-app 0.2.2 → 0.4.1
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/README.md +128 -7
- package/package.json +4 -3
- package/src/index.ts +338 -66
- package/template-api/_github/workflows/ci.yml +0 -3
- package/template-api/_mcp/test/mcp-off.test.ts +13 -0
- package/template-api/_mcp/test/mcp.test.ts +49 -0
- package/template-api/_targets/bun/Dockerfile +13 -0
- package/template-api/_targets/bun/_dockerignore +10 -0
- package/template-api/_targets/bun/src/server.ts +32 -0
- package/template-api/_targets/cloudflare/_github/workflows/ci.yml +24 -0
- package/template-api/_targets/cloudflare/src/index.ts +17 -0
- package/template-api/_targets/node/src/server.ts +55 -0
- package/template-api/_targets/vercel/index.ts +16 -0
- package/template-api/_targets/vercel/vercel.json +4 -0
- package/template-api/src/app.ts +77 -0
- package/template-api/src/env.ts +4 -0
- package/template-api/tsconfig.json +2 -1
- package/template-api/tsconfig.test.json +1 -1
- package/template-full/README.md +155 -0
- package/template-full/_github/workflows/ci.yml +22 -0
- package/template-full/_gitignore +9 -0
- package/template-full/_mcp/test/mcp.test.ts +55 -0
- package/template-full/api/app.ts +132 -0
- package/template-full/api/db/index.ts +10 -0
- package/template-full/api/db/kv.ts +54 -0
- package/template-full/api/db/open.ts +33 -0
- package/template-full/api/db/schema.ts +57 -0
- package/template-full/api/env.ts +44 -0
- package/template-full/api/plans.ts +23 -0
- package/template-full/api/routes/account.ts +63 -0
- package/template-full/api/routes/auth.ts +134 -0
- package/template-full/api/routes/billing.ts +44 -0
- package/template-full/api/routes/notifications.ts +59 -0
- package/template-full/api/routes/privacy.ts +52 -0
- package/template-full/api/server.ts +44 -0
- package/template-full/api/services.ts +185 -0
- package/template-full/biome.json +50 -0
- package/template-full/drizzle/0000_init.sql +155 -0
- package/template-full/drizzle/0001_orgs.sql +47 -0
- package/template-full/drizzle/meta/0000_snapshot.json +974 -0
- package/template-full/drizzle/meta/0001_snapshot.json +1270 -0
- package/template-full/drizzle/meta/_journal.json +20 -0
- package/template-full/drizzle.config.ts +9 -0
- package/template-full/e2e/smoke.spec.ts +152 -0
- package/template-full/index.html +17 -0
- package/template-full/playwright.config.ts +10 -0
- package/template-full/scripts/dev.ts +17 -0
- package/template-full/src/app.css +9 -0
- package/template-full/src/components/toaster.tsx +13 -0
- package/template-full/src/lib/api.ts +40 -0
- package/template-full/src/main.tsx +36 -0
- package/template-full/src/routeTree.gen.ts +297 -0
- package/template-full/src/router.test.ts +23 -0
- package/template-full/src/router.ts +17 -0
- package/template-full/src/routes/__root.tsx +9 -0
- package/template-full/src/routes/_app/account.tsx +64 -0
- package/template-full/src/routes/_app/admin.tsx +38 -0
- package/template-full/src/routes/_app/billing.tsx +40 -0
- package/template-full/src/routes/_app/index.tsx +33 -0
- package/template-full/src/routes/_app/notifications.tsx +72 -0
- package/template-full/src/routes/_app/org/index.tsx +38 -0
- package/template-full/src/routes/_app/org/members.tsx +86 -0
- package/template-full/src/routes/_app/org/new.tsx +45 -0
- package/template-full/src/routes/_app/privacy.tsx +48 -0
- package/template-full/src/routes/_app.tsx +88 -0
- package/template-full/src/routes/invite.$token.tsx +55 -0
- package/template-full/src/routes/login.tsx +36 -0
- package/template-full/test/api.test.ts +189 -0
- package/template-full/tsconfig.api.json +19 -0
- package/template-full/tsconfig.app.json +26 -0
- package/template-full/tsconfig.json +9 -0
- package/template-full/tsconfig.node.json +16 -0
- package/template-full/tsconfig.test.json +8 -0
- package/template-full/vite.config.ts +24 -0
- package/template-api/src/index.ts +0 -55
- /package/template-api/{wrangler.jsonc → _targets/cloudflare/wrangler.jsonc} +0 -0
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ApiKeysManager,
|
|
3
|
+
ProfileCard,
|
|
4
|
+
SessionsList,
|
|
5
|
+
} from "@dapplelight/signet-ui/screens/account-screens"
|
|
6
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
|
7
|
+
import { createFileRoute } from "@tanstack/react-router"
|
|
8
|
+
import { api, meQuery } from "../../lib/api"
|
|
9
|
+
|
|
10
|
+
export const Route = createFileRoute("/_app/account")({
|
|
11
|
+
component: Account,
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
function Account() {
|
|
15
|
+
const qc = useQueryClient()
|
|
16
|
+
const me = useQuery(meQuery).data
|
|
17
|
+
const sessions = useQuery({
|
|
18
|
+
queryKey: ["sessions"],
|
|
19
|
+
queryFn: async () => (await api.sessions.$get()).json(),
|
|
20
|
+
}).data
|
|
21
|
+
const keys = useQuery({
|
|
22
|
+
queryKey: ["api-keys"],
|
|
23
|
+
queryFn: async () => (await api.account["api-keys"].$get()).json(),
|
|
24
|
+
}).data
|
|
25
|
+
const refresh = (key: string) => qc.invalidateQueries({ queryKey: [key] })
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div className="space-y-8">
|
|
29
|
+
{me ? (
|
|
30
|
+
<ProfileCard
|
|
31
|
+
profile={me.user}
|
|
32
|
+
onSave={async ({ name }) => {
|
|
33
|
+
await api.account.me.$patch({ json: { name } })
|
|
34
|
+
await refresh("me")
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
37
|
+
) : null}
|
|
38
|
+
<SessionsList
|
|
39
|
+
sessions={sessions?.sessions ?? []}
|
|
40
|
+
onRevoke={async (s) => {
|
|
41
|
+
await api.sessions[":id"].$delete({ param: { id: s.id } })
|
|
42
|
+
if (s.current) window.location.assign("/login")
|
|
43
|
+
else await refresh("sessions")
|
|
44
|
+
}}
|
|
45
|
+
onRevokeOthers={async () => {
|
|
46
|
+
await api.sessions["revoke-others"].$post()
|
|
47
|
+
await refresh("sessions")
|
|
48
|
+
}}
|
|
49
|
+
/>
|
|
50
|
+
<ApiKeysManager
|
|
51
|
+
keys={keys?.keys ?? []}
|
|
52
|
+
onCreate={async ({ name }) => {
|
|
53
|
+
const { token } = await (await api.account["api-keys"].$post({ json: { name } })).json()
|
|
54
|
+
await refresh("api-keys")
|
|
55
|
+
return { token }
|
|
56
|
+
}}
|
|
57
|
+
onRevoke={async (k) => {
|
|
58
|
+
await api.account["api-keys"][":id"].$delete({ param: { id: k.id } })
|
|
59
|
+
await refresh("api-keys")
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
62
|
+
</div>
|
|
63
|
+
)
|
|
64
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AdminHeader,
|
|
3
|
+
AdminMain,
|
|
4
|
+
AdminNav,
|
|
5
|
+
AdminPager,
|
|
6
|
+
AdminPanel,
|
|
7
|
+
AdminRecordSheet,
|
|
8
|
+
AdminTable,
|
|
9
|
+
AdminToolbar,
|
|
10
|
+
createAdminApi,
|
|
11
|
+
} from "@dapplelight/signet-ui/screens/admin-screens"
|
|
12
|
+
import { createFileRoute } from "@tanstack/react-router"
|
|
13
|
+
|
|
14
|
+
export const Route = createFileRoute("/_app/admin")({
|
|
15
|
+
component: Admin,
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
// The admin API (api/app.ts, /api/admin) is signet-db's defineAdmin over the
|
|
19
|
+
// whole schema: list, search, filter, edit and delete, audited, by role. The
|
|
20
|
+
// panel reads its tables and columns from that API. Drop a part, reorder
|
|
21
|
+
// them, or add your own inside <AdminPanel> (useAdmin() reads its state);
|
|
22
|
+
// <AdminScreen api={adminApi} /> is the same layout in one line.
|
|
23
|
+
const adminApi = createAdminApi({ baseUrl: "/api/admin" })
|
|
24
|
+
|
|
25
|
+
function Admin() {
|
|
26
|
+
return (
|
|
27
|
+
<AdminPanel api={adminApi} defaultTable="users">
|
|
28
|
+
<AdminNav />
|
|
29
|
+
<AdminMain>
|
|
30
|
+
<AdminHeader />
|
|
31
|
+
<AdminToolbar />
|
|
32
|
+
<AdminTable />
|
|
33
|
+
<AdminPager />
|
|
34
|
+
</AdminMain>
|
|
35
|
+
<AdminRecordSheet />
|
|
36
|
+
</AdminPanel>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BillingScreen,
|
|
3
|
+
plansFromEntitlements,
|
|
4
|
+
} from "@dapplelight/signet-ui/screens/billing-screens"
|
|
5
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
|
6
|
+
import { createFileRoute } from "@tanstack/react-router"
|
|
7
|
+
import { toast } from "sonner"
|
|
8
|
+
import { PLAN_DISPLAY, type PlanId, plans } from "../../../api/plans.ts"
|
|
9
|
+
import { api } from "../../lib/api"
|
|
10
|
+
|
|
11
|
+
export const Route = createFileRoute("/_app/billing")({
|
|
12
|
+
component: Billing,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// What each plan allows (definePlans) plus what the page shows (PLAN_DISPLAY),
|
|
16
|
+
// both from api/plans.ts. The current plan and usage come from the API, from
|
|
17
|
+
// signet-db entitlements. With BILLING=fake, checkout switches at once.
|
|
18
|
+
const PLANS = plansFromEntitlements(plans, PLAN_DISPLAY)
|
|
19
|
+
|
|
20
|
+
function Billing() {
|
|
21
|
+
const qc = useQueryClient()
|
|
22
|
+
const data = useQuery({
|
|
23
|
+
queryKey: ["billing"],
|
|
24
|
+
queryFn: async () => (await api.billing.$get()).json(),
|
|
25
|
+
}).data
|
|
26
|
+
if (!data) return null
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<BillingScreen
|
|
30
|
+
plans={PLANS}
|
|
31
|
+
subscription={data.subscription}
|
|
32
|
+
usage={data.usage}
|
|
33
|
+
onSubscribe={async (plan) => {
|
|
34
|
+
await api.billing.checkout.$post({ json: { plan: plan.key as PlanId } })
|
|
35
|
+
await qc.invalidateQueries()
|
|
36
|
+
toast.success(`You are on ${plan.name}`)
|
|
37
|
+
}}
|
|
38
|
+
/>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Card, CardContent, CardHeader, CardTitle } from "@dapplelight/signet-ui/components/card"
|
|
2
|
+
import { useQuery } from "@tanstack/react-query"
|
|
3
|
+
import { createFileRoute, Link } from "@tanstack/react-router"
|
|
4
|
+
import { meQuery } from "../../lib/api"
|
|
5
|
+
|
|
6
|
+
export const Route = createFileRoute("/_app/")({
|
|
7
|
+
component: Home,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
// Your product goes here. Sign-in, account, inbox, privacy, billing and admin
|
|
11
|
+
// are already wired; this page is the one that is yours.
|
|
12
|
+
function Home() {
|
|
13
|
+
const me = useQuery(meQuery).data
|
|
14
|
+
return (
|
|
15
|
+
<Card>
|
|
16
|
+
<CardHeader>
|
|
17
|
+
<CardTitle>Hello{me?.user.name ? `, ${me.user.name}` : ""}</CardTitle>
|
|
18
|
+
</CardHeader>
|
|
19
|
+
<CardContent className="space-y-2 text-sm text-muted-foreground">
|
|
20
|
+
<p>
|
|
21
|
+
You are on the <strong className="text-foreground">{me?.plan ?? "…"}</strong> plan.{" "}
|
|
22
|
+
<Link to="/billing" className="underline">
|
|
23
|
+
See plans
|
|
24
|
+
</Link>
|
|
25
|
+
</p>
|
|
26
|
+
<p>
|
|
27
|
+
Replace this page with your product: <code>src/routes/_app/index.tsx</code>, backed by a
|
|
28
|
+
route in <code>api/app.ts</code>.
|
|
29
|
+
</p>
|
|
30
|
+
</CardContent>
|
|
31
|
+
</Card>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NotificationInbox,
|
|
3
|
+
NotificationPreferences,
|
|
4
|
+
} from "@dapplelight/signet-ui/screens/notification-screens"
|
|
5
|
+
import { useInfiniteQuery, useQuery, useQueryClient } from "@tanstack/react-query"
|
|
6
|
+
import { createFileRoute, useNavigate } from "@tanstack/react-router"
|
|
7
|
+
import { api } from "../../lib/api"
|
|
8
|
+
|
|
9
|
+
export const Route = createFileRoute("/_app/notifications")({
|
|
10
|
+
component: Notifications,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
// Categories match the `category` of each template in api/services.ts.
|
|
14
|
+
const CATEGORIES = [
|
|
15
|
+
{ id: "account", label: "Account", description: "Sign-ins and profile changes" },
|
|
16
|
+
{ id: "billing", label: "Billing", description: "Plan changes and receipts", required: true },
|
|
17
|
+
]
|
|
18
|
+
|
|
19
|
+
function Notifications() {
|
|
20
|
+
const qc = useQueryClient()
|
|
21
|
+
const navigate = useNavigate()
|
|
22
|
+
const inbox = useInfiniteQuery({
|
|
23
|
+
queryKey: ["notifications", "inbox"],
|
|
24
|
+
initialPageParam: undefined as string | undefined,
|
|
25
|
+
queryFn: async ({ pageParam }) =>
|
|
26
|
+
(await api.notifications.$get({ query: pageParam ? { cursor: pageParam } : {} })).json(),
|
|
27
|
+
getNextPageParam: (last) => last.nextCursor,
|
|
28
|
+
})
|
|
29
|
+
const prefs = useQuery({
|
|
30
|
+
queryKey: ["notification-prefs"],
|
|
31
|
+
queryFn: async () => (await api.notifications.prefs.$get()).json(),
|
|
32
|
+
}).data
|
|
33
|
+
const refresh = () => qc.invalidateQueries({ queryKey: ["notifications"] })
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div className="space-y-10">
|
|
37
|
+
<NotificationInbox
|
|
38
|
+
items={inbox.data?.pages.flatMap((p) => p.items) ?? []}
|
|
39
|
+
unreadCount={inbox.data?.pages[0]?.unreadCount}
|
|
40
|
+
hasMore={inbox.hasNextPage}
|
|
41
|
+
onLoadMore={() => inbox.fetchNextPage()}
|
|
42
|
+
onMarkRead={async (ids) => {
|
|
43
|
+
await api.notifications.read.$post({ json: { ids } })
|
|
44
|
+
await refresh()
|
|
45
|
+
}}
|
|
46
|
+
onMarkAllRead={async () => {
|
|
47
|
+
await api.notifications["read-all"].$post()
|
|
48
|
+
await refresh()
|
|
49
|
+
}}
|
|
50
|
+
onArchive={async (item) => {
|
|
51
|
+
await api.notifications[":id"].archive.$post({ param: { id: item.id } })
|
|
52
|
+
await refresh()
|
|
53
|
+
}}
|
|
54
|
+
onOpen={(item) => {
|
|
55
|
+
if (item.link) navigate({ to: item.link })
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
{prefs ? (
|
|
59
|
+
<NotificationPreferences
|
|
60
|
+
categories={CATEGORIES}
|
|
61
|
+
channels={["inApp", "email", "sms"]}
|
|
62
|
+
defaultValue={prefs.channels}
|
|
63
|
+
onToggle={async ({ category, channel, on }) => {
|
|
64
|
+
await api.notifications.prefs.$put({
|
|
65
|
+
json: { channels: { [category]: { [channel]: on } } },
|
|
66
|
+
})
|
|
67
|
+
}}
|
|
68
|
+
/>
|
|
69
|
+
) : null}
|
|
70
|
+
</div>
|
|
71
|
+
)
|
|
72
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { OrgSettings } from "@dapplelight/signet-ui/screens/org-screens"
|
|
2
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
|
3
|
+
import { createFileRoute, Link } from "@tanstack/react-router"
|
|
4
|
+
import { api, currentOrgQuery } from "../../../lib/api"
|
|
5
|
+
|
|
6
|
+
export const Route = createFileRoute("/_app/org/")({
|
|
7
|
+
component: OrgPage,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
// The current org's settings: name, theme, brand colour. The API
|
|
11
|
+
// (/api/orgs/current) checks membership and org:update; without it the form is
|
|
12
|
+
// read-only. A custom domain is not editable here: an operator sets it with
|
|
13
|
+
// orgs.update, and tenant() (api/app.ts) then resolves the org from the host.
|
|
14
|
+
function OrgPage() {
|
|
15
|
+
const qc = useQueryClient()
|
|
16
|
+
const current = useQuery(currentOrgQuery).data
|
|
17
|
+
if (!current) return null
|
|
18
|
+
const canEdit = current.permissions.includes("*") || current.permissions.includes("org:update")
|
|
19
|
+
return (
|
|
20
|
+
<div className="space-y-4">
|
|
21
|
+
<nav className="flex gap-3 text-sm">
|
|
22
|
+
<span className="font-medium">Settings</span>
|
|
23
|
+
<Link to="/org/members" className="text-muted-foreground underline">
|
|
24
|
+
Members and invites
|
|
25
|
+
</Link>
|
|
26
|
+
</nav>
|
|
27
|
+
<OrgSettings
|
|
28
|
+
key={current.org.id}
|
|
29
|
+
org={current.org}
|
|
30
|
+
readOnly={!canEdit}
|
|
31
|
+
onSave={async (changes) => {
|
|
32
|
+
await api.orgs.current.$patch({ json: changes })
|
|
33
|
+
await qc.invalidateQueries({ queryKey: ["orgs"] })
|
|
34
|
+
}}
|
|
35
|
+
/>
|
|
36
|
+
</div>
|
|
37
|
+
)
|
|
38
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { InviteDialog, MembersList } from "@dapplelight/signet-ui/screens/org-screens"
|
|
2
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
|
3
|
+
import { createFileRoute, Link } from "@tanstack/react-router"
|
|
4
|
+
import { useState } from "react"
|
|
5
|
+
import { api, currentOrgQuery, meQuery } from "../../../lib/api"
|
|
6
|
+
|
|
7
|
+
export const Route = createFileRoute("/_app/org/members")({
|
|
8
|
+
component: Members,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
const can = (perms: string[], p: string) =>
|
|
12
|
+
perms.includes("*") || perms.includes(p) || perms.includes(`${p.split(":")[0]}:*`)
|
|
13
|
+
|
|
14
|
+
// Members, their roles and pending invites of the current org. The API
|
|
15
|
+
// guards each call (members:read, members:manage, members:invite) and refuses
|
|
16
|
+
// a role with more permissions than your own; the page only hides what you
|
|
17
|
+
// cannot do.
|
|
18
|
+
function Members() {
|
|
19
|
+
const qc = useQueryClient()
|
|
20
|
+
const me = useQuery(meQuery).data
|
|
21
|
+
const current = useQuery(currentOrgQuery).data
|
|
22
|
+
const perms = current?.permissions ?? []
|
|
23
|
+
const members = useQuery({
|
|
24
|
+
queryKey: ["orgs", "members"],
|
|
25
|
+
queryFn: async () => (await api.orgs.current.members.$get()).json(),
|
|
26
|
+
enabled: can(perms, "members:read"),
|
|
27
|
+
}).data
|
|
28
|
+
const invites = useQuery({
|
|
29
|
+
queryKey: ["orgs", "invites"],
|
|
30
|
+
queryFn: async () => (await api.orgs.current.invites.$get()).json(),
|
|
31
|
+
enabled: can(perms, "members:invite"),
|
|
32
|
+
}).data
|
|
33
|
+
const [inviting, setInviting] = useState(false)
|
|
34
|
+
const refresh = () => qc.invalidateQueries({ queryKey: ["orgs"] })
|
|
35
|
+
if (!current) return null
|
|
36
|
+
const roles = Object.keys(current.roles)
|
|
37
|
+
return (
|
|
38
|
+
<div className="space-y-4">
|
|
39
|
+
<nav className="flex gap-3 text-sm">
|
|
40
|
+
<Link to="/org" className="text-muted-foreground underline">
|
|
41
|
+
Settings
|
|
42
|
+
</Link>
|
|
43
|
+
<span className="font-medium">Members and invites</span>
|
|
44
|
+
</nav>
|
|
45
|
+
<MembersList
|
|
46
|
+
members={members?.members ?? []}
|
|
47
|
+
roles={roles}
|
|
48
|
+
currentUserId={me?.user.id}
|
|
49
|
+
canManage={can(perms, "members:manage")}
|
|
50
|
+
invitations={invites?.invitations ?? []}
|
|
51
|
+
onInvite={can(perms, "members:invite") ? () => setInviting(true) : undefined}
|
|
52
|
+
onRoleChange={async (m, role) => {
|
|
53
|
+
// orgRoutes validates its own bodies, so the client types only the param.
|
|
54
|
+
await api.orgs.current.members[":userId"].$patch({
|
|
55
|
+
param: { userId: m.userId },
|
|
56
|
+
json: { role },
|
|
57
|
+
} as never)
|
|
58
|
+
await refresh()
|
|
59
|
+
}}
|
|
60
|
+
onRemove={async (m) => {
|
|
61
|
+
await api.orgs.current.members[":userId"].$delete({ param: { userId: m.userId } })
|
|
62
|
+
if (m.userId === me?.user.id) window.location.assign("/")
|
|
63
|
+
else await refresh()
|
|
64
|
+
}}
|
|
65
|
+
onRevokeInvite={async (i) => {
|
|
66
|
+
await api.orgs.current.invites[":id"].$delete({ param: { id: i.id } })
|
|
67
|
+
await refresh()
|
|
68
|
+
}}
|
|
69
|
+
/>
|
|
70
|
+
<InviteDialog
|
|
71
|
+
open={inviting}
|
|
72
|
+
onOpenChange={setInviting}
|
|
73
|
+
roles={roles.filter((r) => r !== "owner")}
|
|
74
|
+
defaultRole="member"
|
|
75
|
+
// Sign-in is by phone, so there is no verified email to bind an invite
|
|
76
|
+
// to: invites are links. Send them yourself, or wire orgRoutes' onInvite.
|
|
77
|
+
askEmail={false}
|
|
78
|
+
onInvite={async ({ role }) => {
|
|
79
|
+
const { token } = await (await api.orgs.current.invites.$post({ json: { role } })).json()
|
|
80
|
+
await refresh()
|
|
81
|
+
return { link: `${window.location.origin}/invite/${token}` }
|
|
82
|
+
}}
|
|
83
|
+
/>
|
|
84
|
+
</div>
|
|
85
|
+
)
|
|
86
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { Button } from "@dapplelight/signet-ui/components/button"
|
|
2
|
+
import { Field, FieldControl, FieldLabel } from "@dapplelight/signet-ui/components/field"
|
|
3
|
+
import { createFileRoute } from "@tanstack/react-router"
|
|
4
|
+
import { useState } from "react"
|
|
5
|
+
import { api, switchOrg } from "../../../lib/api"
|
|
6
|
+
|
|
7
|
+
export const Route = createFileRoute("/_app/org/new")({
|
|
8
|
+
component: NewOrg,
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
// A new org with you as its owner; the app switches to it.
|
|
12
|
+
function NewOrg() {
|
|
13
|
+
const [name, setName] = useState("")
|
|
14
|
+
const [pending, setPending] = useState(false)
|
|
15
|
+
return (
|
|
16
|
+
<form
|
|
17
|
+
className="max-w-sm space-y-4"
|
|
18
|
+
onSubmit={async (e) => {
|
|
19
|
+
e.preventDefault()
|
|
20
|
+
if (!name.trim()) return
|
|
21
|
+
setPending(true)
|
|
22
|
+
try {
|
|
23
|
+
const { org } = await (await api.orgs.$post({ json: { name: name.trim() } })).json()
|
|
24
|
+
await switchOrg(org.id, "/org")
|
|
25
|
+
} finally {
|
|
26
|
+
setPending(false)
|
|
27
|
+
}
|
|
28
|
+
}}
|
|
29
|
+
>
|
|
30
|
+
<h1 className="text-lg font-semibold">New organisation</h1>
|
|
31
|
+
<Field>
|
|
32
|
+
<FieldLabel>Name</FieldLabel>
|
|
33
|
+
<FieldControl
|
|
34
|
+
required
|
|
35
|
+
maxLength={100}
|
|
36
|
+
value={name}
|
|
37
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setName(e.target.value)}
|
|
38
|
+
/>
|
|
39
|
+
</Field>
|
|
40
|
+
<Button type="submit" disabled={pending || !name.trim()}>
|
|
41
|
+
Create
|
|
42
|
+
</Button>
|
|
43
|
+
</form>
|
|
44
|
+
)
|
|
45
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { ConsentList, DataRequests } from "@dapplelight/signet-ui/screens/privacy-screens"
|
|
2
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query"
|
|
3
|
+
import { createFileRoute } from "@tanstack/react-router"
|
|
4
|
+
import { api } from "../../lib/api"
|
|
5
|
+
|
|
6
|
+
export const Route = createFileRoute("/_app/privacy")({
|
|
7
|
+
component: Privacy,
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
// DPDP consent (withdrawing is one switch) and data export / erasure
|
|
11
|
+
// requests. Staff fulfil requests; see README, "Privacy requests".
|
|
12
|
+
function Privacy() {
|
|
13
|
+
const qc = useQueryClient()
|
|
14
|
+
const data = useQuery({
|
|
15
|
+
queryKey: ["privacy"],
|
|
16
|
+
queryFn: async () => (await api.privacy.$get()).json(),
|
|
17
|
+
}).data
|
|
18
|
+
const refresh = () => qc.invalidateQueries({ queryKey: ["privacy"] })
|
|
19
|
+
if (!data) return null
|
|
20
|
+
|
|
21
|
+
return (
|
|
22
|
+
<div className="space-y-10">
|
|
23
|
+
<ConsentList
|
|
24
|
+
purposes={data.purposes}
|
|
25
|
+
consents={data.consents}
|
|
26
|
+
onGive={async (purpose) => {
|
|
27
|
+
await api.privacy.consents[":purpose"].$post({ param: { purpose } })
|
|
28
|
+
await refresh()
|
|
29
|
+
}}
|
|
30
|
+
onWithdraw={async (purpose) => {
|
|
31
|
+
await api.privacy.consents[":purpose"].$delete({ param: { purpose } })
|
|
32
|
+
await refresh()
|
|
33
|
+
}}
|
|
34
|
+
/>
|
|
35
|
+
<DataRequests
|
|
36
|
+
requests={data.requests}
|
|
37
|
+
onRequestExport={async () => {
|
|
38
|
+
await api.privacy.requests.$post({ json: { kind: "export" } })
|
|
39
|
+
await refresh()
|
|
40
|
+
}}
|
|
41
|
+
onRequestErasure={async () => {
|
|
42
|
+
await api.privacy.requests.$post({ json: { kind: "erasure" } })
|
|
43
|
+
await refresh()
|
|
44
|
+
}}
|
|
45
|
+
/>
|
|
46
|
+
</div>
|
|
47
|
+
)
|
|
48
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Badge } from "@dapplelight/signet-ui/components/badge"
|
|
2
|
+
import { Button } from "@dapplelight/signet-ui/components/button"
|
|
3
|
+
import { ThemeToggle } from "@dapplelight/signet-ui/components/theme-toggle"
|
|
4
|
+
import { OrgSwitcher } from "@dapplelight/signet-ui/screens/org-screens"
|
|
5
|
+
import { useQuery } from "@tanstack/react-query"
|
|
6
|
+
import { createFileRoute, Link, Outlet, useNavigate } from "@tanstack/react-router"
|
|
7
|
+
import { api, currentOrgQuery, meQuery, orgsQuery, switchOrg } from "../lib/api"
|
|
8
|
+
|
|
9
|
+
// The signed-in shell. Every page under routes/_app/ renders inside it; a
|
|
10
|
+
// 401 from any of their queries sends the browser to /login (main.tsx).
|
|
11
|
+
export const Route = createFileRoute("/_app")({
|
|
12
|
+
component: AppLayout,
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
const NAV = [
|
|
16
|
+
{ to: "/", label: "Home" },
|
|
17
|
+
{ to: "/notifications", label: "Inbox" },
|
|
18
|
+
{ to: "/billing", label: "Billing" },
|
|
19
|
+
{ to: "/account", label: "Account" },
|
|
20
|
+
{ to: "/privacy", label: "Privacy" },
|
|
21
|
+
{ to: "/org", label: "Org" },
|
|
22
|
+
] as const
|
|
23
|
+
|
|
24
|
+
function AppLayout() {
|
|
25
|
+
const me = useQuery(meQuery)
|
|
26
|
+
const unread = useQuery({
|
|
27
|
+
queryKey: ["notifications", "count"],
|
|
28
|
+
queryFn: async () => (await api.notifications.$get({ query: {} })).json(),
|
|
29
|
+
}).data?.unreadCount
|
|
30
|
+
const staff = me.data && me.data.user.role !== "user"
|
|
31
|
+
const navigate = useNavigate()
|
|
32
|
+
const orgs = useQuery(orgsQuery).data?.orgs ?? []
|
|
33
|
+
const current = useQuery({ ...currentOrgQuery, retry: false }).data
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<>
|
|
37
|
+
<header className="flex flex-wrap items-center gap-4 border-b border-border px-6 py-3">
|
|
38
|
+
<Link to="/" className="font-medium">
|
|
39
|
+
__APP_NAME__
|
|
40
|
+
</Link>
|
|
41
|
+
{/* Every org you belong to; switching reloads into the other one. */}
|
|
42
|
+
<OrgSwitcher
|
|
43
|
+
className="w-48"
|
|
44
|
+
orgs={orgs}
|
|
45
|
+
currentId={current?.org.id ?? null}
|
|
46
|
+
onSwitch={(id) => switchOrg(id)}
|
|
47
|
+
onCreate={() => navigate({ to: "/org/new" })}
|
|
48
|
+
/>
|
|
49
|
+
<nav className="flex flex-1 flex-wrap items-center gap-1 text-sm">
|
|
50
|
+
{NAV.map((n) => (
|
|
51
|
+
<Link
|
|
52
|
+
key={n.to}
|
|
53
|
+
to={n.to}
|
|
54
|
+
className="rounded-md px-2 py-1 text-muted-foreground data-[status=active]:bg-muted data-[status=active]:text-foreground"
|
|
55
|
+
>
|
|
56
|
+
{n.label}
|
|
57
|
+
{n.to === "/notifications" && unread ? (
|
|
58
|
+
<Badge className="ml-1">{unread}</Badge>
|
|
59
|
+
) : null}
|
|
60
|
+
</Link>
|
|
61
|
+
))}
|
|
62
|
+
{staff ? (
|
|
63
|
+
<Link
|
|
64
|
+
to="/admin"
|
|
65
|
+
className="rounded-md px-2 py-1 text-muted-foreground data-[status=active]:bg-muted data-[status=active]:text-foreground"
|
|
66
|
+
>
|
|
67
|
+
Admin
|
|
68
|
+
</Link>
|
|
69
|
+
) : null}
|
|
70
|
+
</nav>
|
|
71
|
+
<ThemeToggle />
|
|
72
|
+
<Button
|
|
73
|
+
variant="ghost"
|
|
74
|
+
size="sm"
|
|
75
|
+
onClick={async () => {
|
|
76
|
+
await api.auth["sign-out"].$post()
|
|
77
|
+
window.location.assign("/login")
|
|
78
|
+
}}
|
|
79
|
+
>
|
|
80
|
+
Sign out
|
|
81
|
+
</Button>
|
|
82
|
+
</header>
|
|
83
|
+
<main className="mx-auto max-w-3xl p-6">
|
|
84
|
+
<Outlet />
|
|
85
|
+
</main>
|
|
86
|
+
</>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AcceptInvitePage,
|
|
3
|
+
type AcceptInvitePageProps,
|
|
4
|
+
} from "@dapplelight/signet-ui/screens/org-screens"
|
|
5
|
+
import { useQuery } from "@tanstack/react-query"
|
|
6
|
+
import { createFileRoute } from "@tanstack/react-router"
|
|
7
|
+
import { ApiError, AuthError, api } from "../lib/api"
|
|
8
|
+
|
|
9
|
+
export const Route = createFileRoute("/invite/$token")({
|
|
10
|
+
component: Invite,
|
|
11
|
+
})
|
|
12
|
+
|
|
13
|
+
type Reason = NonNullable<AcceptInvitePageProps["error"]>
|
|
14
|
+
|
|
15
|
+
// The invite link. Anyone can see what it is for; accepting needs a signed-in
|
|
16
|
+
// user, so a signed-out visitor goes to /login and comes back here.
|
|
17
|
+
function Invite() {
|
|
18
|
+
const { token } = Route.useParams()
|
|
19
|
+
const preview = useQuery({
|
|
20
|
+
queryKey: ["invite", token],
|
|
21
|
+
queryFn: async () => (await api.orgs.invites[":token"].$get({ param: { token } })).json(),
|
|
22
|
+
retry: false,
|
|
23
|
+
})
|
|
24
|
+
const here = `/invite/${encodeURIComponent(token)}`
|
|
25
|
+
const status = preview.data?.status
|
|
26
|
+
return (
|
|
27
|
+
<AcceptInvitePage
|
|
28
|
+
org={preview.data?.org}
|
|
29
|
+
invite={{
|
|
30
|
+
role: preview.data?.role ?? null,
|
|
31
|
+
...(preview.data ? { expiresAt: preview.data.expiresAt } : {}),
|
|
32
|
+
}}
|
|
33
|
+
{...(preview.isError
|
|
34
|
+
? { error: "not_found" as const }
|
|
35
|
+
: status && status !== "pending"
|
|
36
|
+
? { error: (status === "accepted" ? "used" : status) as Reason }
|
|
37
|
+
: {})}
|
|
38
|
+
onAccept={async () => {
|
|
39
|
+
try {
|
|
40
|
+
await api.orgs.invites[":token"].accept.$post({ param: { token } })
|
|
41
|
+
return { ok: true }
|
|
42
|
+
} catch (e) {
|
|
43
|
+
if (e instanceof AuthError) {
|
|
44
|
+
window.location.assign(`/login?next=${encodeURIComponent(here)}`)
|
|
45
|
+
return new Promise(() => {}) // the page is leaving
|
|
46
|
+
}
|
|
47
|
+
if (e instanceof ApiError && e.code?.startsWith("INVITE_"))
|
|
48
|
+
return { ok: false, reason: e.code.slice(7).toLowerCase() as Reason }
|
|
49
|
+
throw e
|
|
50
|
+
}
|
|
51
|
+
}}
|
|
52
|
+
onAccepted={() => window.location.assign("/")}
|
|
53
|
+
/>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { AuthScreen } from "@dapplelight/signet-ui/screens/auth-screens"
|
|
2
|
+
import { createFileRoute } from "@tanstack/react-router"
|
|
3
|
+
import { api } from "../lib/api"
|
|
4
|
+
|
|
5
|
+
// Phone one-time-code sign-in against api/routes/auth.ts. In development the
|
|
6
|
+
// code is printed in the API's console. Add email or OAuth through
|
|
7
|
+
// AuthScreen's `channels` and `providers` once the API has them.
|
|
8
|
+
export const Route = createFileRoute("/login")({
|
|
9
|
+
component: Login,
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
function Login() {
|
|
13
|
+
return (
|
|
14
|
+
<main className="grid min-h-dvh place-items-center p-6">
|
|
15
|
+
<AuthScreen
|
|
16
|
+
channels={["phone"]}
|
|
17
|
+
hideModeSwitch
|
|
18
|
+
labels={{ signInTitle: "Sign in to __APP_NAME__" }}
|
|
19
|
+
onRequestCode={async ({ to }) => {
|
|
20
|
+
await api.auth.otp.$post({ json: { phone: to } })
|
|
21
|
+
}}
|
|
22
|
+
onVerify={async ({ to, code }) => {
|
|
23
|
+
await api.auth.verify.$post({ json: { phone: to, code } })
|
|
24
|
+
// A full load, so no query from before sign-in survives. `?next=`
|
|
25
|
+
// (an invite link) brings the user back; only same-site paths.
|
|
26
|
+
const next = new URLSearchParams(window.location.search).get("next")
|
|
27
|
+
// Browsers read `\` as `/`, so `/\evil.com` is off-site: resolve and compare origins.
|
|
28
|
+
const url = new URL(next ?? "/", window.location.origin)
|
|
29
|
+
window.location.assign(
|
|
30
|
+
url.origin === window.location.origin ? url.pathname + url.search + url.hash : "/",
|
|
31
|
+
)
|
|
32
|
+
}}
|
|
33
|
+
/>
|
|
34
|
+
</main>
|
|
35
|
+
)
|
|
36
|
+
}
|