@codelitdev/platform-cli 0.1.0-alpha.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/LICENSE +21 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +43 -0
- package/dist/codemod-readme-title.d.ts +5 -0
- package/dist/codemod-readme-title.js +21 -0
- package/dist/create.d.ts +6 -0
- package/dist/create.js +124 -0
- package/dist/doctor.d.ts +12 -0
- package/dist/doctor.js +111 -0
- package/dist/fs.d.ts +5 -0
- package/dist/fs.js +42 -0
- package/dist/git.d.ts +1 -0
- package/dist/git.js +19 -0
- package/dist/hash.d.ts +2 -0
- package/dist/hash.js +8 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/manifest.d.ts +12 -0
- package/dist/manifest.js +31 -0
- package/dist/template.d.ts +2 -0
- package/dist/template.js +23 -0
- package/dist/upgrade.d.ts +13 -0
- package/dist/upgrade.js +97 -0
- package/package.json +41 -0
- package/template/.github/workflows/platform-conformance.yml +28 -0
- package/template/README.md +5 -0
- package/template/apps/api/.env.example +18 -0
- package/template/apps/api/README.md +3 -0
- package/template/apps/api/billing.config.ts +25 -0
- package/template/apps/api/drizzle.config.ts +7 -0
- package/template/apps/api/package.json +53 -0
- package/template/apps/api/scripts/generate-auth-schema.mjs +173 -0
- package/template/apps/api/scripts/migrate.mjs +15 -0
- package/template/apps/api/src/app.test.ts +479 -0
- package/template/apps/api/src/auth/api-keys.ts +131 -0
- package/template/apps/api/src/auth/authenticate.ts +166 -0
- package/template/apps/api/src/auth/better-auth.ts +38 -0
- package/template/apps/api/src/auth/oauth.ts +9 -0
- package/template/apps/api/src/auth/options.ts +69 -0
- package/template/apps/api/src/billing.ts +58 -0
- package/template/apps/api/src/conformance-adapter.ts +335 -0
- package/template/apps/api/src/db/migrate.ts +26 -0
- package/template/apps/api/src/db/migrations/0000_application.sql +72 -0
- package/template/apps/api/src/db/migrations/0000_auth.sql +178 -0
- package/template/apps/api/src/db/migrations/0001_billing.sql +234 -0
- package/template/apps/api/src/db/schema/auth.generated.ts +185 -0
- package/template/apps/api/src/db/schema/billing.generated.ts +447 -0
- package/template/apps/api/src/db/schema/index.ts +3 -0
- package/template/apps/api/src/db/schema/notes.ts +31 -0
- package/template/apps/api/src/db/schema/tenants.ts +83 -0
- package/template/apps/api/src/deps.ts +12 -0
- package/template/apps/api/src/dispatch.ts +476 -0
- package/template/apps/api/src/express-app.ts +161 -0
- package/template/apps/api/src/invitations.ts +217 -0
- package/template/apps/api/src/logger.ts +26 -0
- package/template/apps/api/src/main.ts +98 -0
- package/template/apps/api/src/mcp.ts +127 -0
- package/template/apps/api/src/notes.ts +251 -0
- package/template/apps/api/src/openapi.ts +12 -0
- package/template/apps/api/src/permissions.ts +35 -0
- package/template/apps/api/src/runtime.ts +167 -0
- package/template/apps/api/src/seed.ts +340 -0
- package/template/apps/api/src/tenancy.ts +116 -0
- package/template/apps/api/src/types.ts +20 -0
- package/template/apps/api/src/worker.ts +57 -0
- package/template/apps/api/tsconfig.json +14 -0
- package/template/apps/web/.env.example +7 -0
- package/template/apps/web/app/api/[...path]/route.ts +51 -0
- package/template/apps/web/app/globals.css +156 -0
- package/template/apps/web/app/layout.tsx +34 -0
- package/template/apps/web/app/login/page.tsx +127 -0
- package/template/apps/web/app/notes/page.tsx +93 -0
- package/template/apps/web/app/page.tsx +80 -0
- package/template/apps/web/components/auth-gate.tsx +34 -0
- package/template/apps/web/components/browser-observability.tsx +53 -0
- package/template/apps/web/components/tenant-switcher.tsx +51 -0
- package/template/apps/web/lib/observability-config.ts +15 -0
- package/template/apps/web/next-env.d.ts +2 -0
- package/template/apps/web/next.config.ts +7 -0
- package/template/apps/web/package.json +26 -0
- package/template/apps/web/tsconfig.json +21 -0
- package/template/biome.template.json +50 -0
- package/template/docker-compose.yml +14 -0
- package/template/package.json +40 -0
- package/template/packages/api-contract/package.json +23 -0
- package/template/packages/api-contract/src/index.ts +256 -0
- package/template/packages/api-contract/src/mcp-parity.ts +158 -0
- package/template/packages/api-contract/tsconfig.json +11 -0
- package/template/patches/@anatine__zod-openapi@1.14.2.patch +14 -0
- package/template/tooling/platform/config.ts +2 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--ink: #182230;
|
|
3
|
+
--muted: #667085;
|
|
4
|
+
--line: #e4e7ec;
|
|
5
|
+
--surface: #ffffff;
|
|
6
|
+
--canvas: #f5f7fa;
|
|
7
|
+
--accent: #c9781e;
|
|
8
|
+
}
|
|
9
|
+
* {
|
|
10
|
+
box-sizing: border-box;
|
|
11
|
+
}
|
|
12
|
+
html,
|
|
13
|
+
body {
|
|
14
|
+
min-height: 100%;
|
|
15
|
+
}
|
|
16
|
+
body {
|
|
17
|
+
margin: 0;
|
|
18
|
+
background: var(--canvas);
|
|
19
|
+
color: var(--ink);
|
|
20
|
+
font-family: Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
|
|
21
|
+
}
|
|
22
|
+
a {
|
|
23
|
+
color: #9a5a12;
|
|
24
|
+
}
|
|
25
|
+
main {
|
|
26
|
+
width: min(100% - 32px, 980px);
|
|
27
|
+
margin: 0 auto;
|
|
28
|
+
padding: 48px 0;
|
|
29
|
+
}
|
|
30
|
+
.page-shell {
|
|
31
|
+
display: grid;
|
|
32
|
+
gap: 28px;
|
|
33
|
+
}
|
|
34
|
+
.app-header {
|
|
35
|
+
display: flex;
|
|
36
|
+
justify-content: space-between;
|
|
37
|
+
align-items: center;
|
|
38
|
+
gap: 16px;
|
|
39
|
+
}
|
|
40
|
+
.eyebrow {
|
|
41
|
+
margin: 0 0 6px;
|
|
42
|
+
color: var(--muted);
|
|
43
|
+
font-size: 13px;
|
|
44
|
+
font-weight: 700;
|
|
45
|
+
letter-spacing: 0.08em;
|
|
46
|
+
text-transform: uppercase;
|
|
47
|
+
}
|
|
48
|
+
h1 {
|
|
49
|
+
margin: 0;
|
|
50
|
+
font-size: clamp(28px, 4vw, 40px);
|
|
51
|
+
letter-spacing: -0.03em;
|
|
52
|
+
}
|
|
53
|
+
h2 {
|
|
54
|
+
margin: 0;
|
|
55
|
+
font-size: 20px;
|
|
56
|
+
}
|
|
57
|
+
.subtitle {
|
|
58
|
+
margin: 8px 0 0;
|
|
59
|
+
color: var(--muted);
|
|
60
|
+
}
|
|
61
|
+
.card {
|
|
62
|
+
padding: 24px;
|
|
63
|
+
border: 1px solid var(--line);
|
|
64
|
+
border-radius: 16px;
|
|
65
|
+
background: var(--surface);
|
|
66
|
+
box-shadow: 0 8px 24px rgb(16 24 40 / 5%);
|
|
67
|
+
}
|
|
68
|
+
.stack {
|
|
69
|
+
display: grid;
|
|
70
|
+
gap: 18px;
|
|
71
|
+
}
|
|
72
|
+
.toolbar,
|
|
73
|
+
form {
|
|
74
|
+
display: flex;
|
|
75
|
+
flex-wrap: wrap;
|
|
76
|
+
align-items: flex-end;
|
|
77
|
+
gap: 12px;
|
|
78
|
+
}
|
|
79
|
+
label {
|
|
80
|
+
display: grid;
|
|
81
|
+
gap: 7px;
|
|
82
|
+
color: #344054;
|
|
83
|
+
font-size: 14px;
|
|
84
|
+
font-weight: 600;
|
|
85
|
+
}
|
|
86
|
+
input,
|
|
87
|
+
select,
|
|
88
|
+
textarea {
|
|
89
|
+
min-height: 42px;
|
|
90
|
+
width: 100%;
|
|
91
|
+
padding: 9px 11px;
|
|
92
|
+
border: 1px solid #d0d5dd;
|
|
93
|
+
border-radius: 8px;
|
|
94
|
+
background: #fff;
|
|
95
|
+
color: var(--ink);
|
|
96
|
+
font: inherit;
|
|
97
|
+
}
|
|
98
|
+
textarea {
|
|
99
|
+
min-height: 110px;
|
|
100
|
+
resize: vertical;
|
|
101
|
+
}
|
|
102
|
+
input:focus,
|
|
103
|
+
select:focus,
|
|
104
|
+
textarea:focus {
|
|
105
|
+
outline: 3px solid rgb(201 120 30 / 18%);
|
|
106
|
+
border-color: var(--accent);
|
|
107
|
+
}
|
|
108
|
+
.field {
|
|
109
|
+
flex: 1 1 220px;
|
|
110
|
+
}
|
|
111
|
+
.muted {
|
|
112
|
+
color: var(--muted);
|
|
113
|
+
}
|
|
114
|
+
.note-list {
|
|
115
|
+
display: grid;
|
|
116
|
+
gap: 12px;
|
|
117
|
+
padding: 0;
|
|
118
|
+
margin: 0;
|
|
119
|
+
list-style: none;
|
|
120
|
+
}
|
|
121
|
+
.note-item {
|
|
122
|
+
padding: 16px;
|
|
123
|
+
border: 1px solid var(--line);
|
|
124
|
+
border-radius: 10px;
|
|
125
|
+
background: #fcfcfd;
|
|
126
|
+
}
|
|
127
|
+
.note-item strong {
|
|
128
|
+
display: block;
|
|
129
|
+
margin-bottom: 4px;
|
|
130
|
+
}
|
|
131
|
+
.auth-page {
|
|
132
|
+
display: grid;
|
|
133
|
+
min-height: 100vh;
|
|
134
|
+
place-items: center;
|
|
135
|
+
padding-block: 24px;
|
|
136
|
+
}
|
|
137
|
+
.auth-card {
|
|
138
|
+
width: min(100%, 460px);
|
|
139
|
+
}
|
|
140
|
+
.auth-card form {
|
|
141
|
+
display: grid;
|
|
142
|
+
align-items: stretch;
|
|
143
|
+
}
|
|
144
|
+
.auth-card details {
|
|
145
|
+
margin-top: 20px;
|
|
146
|
+
padding-top: 18px;
|
|
147
|
+
border-top: 1px solid var(--line);
|
|
148
|
+
}
|
|
149
|
+
.auth-card summary {
|
|
150
|
+
cursor: pointer;
|
|
151
|
+
color: #9a5a12;
|
|
152
|
+
font-weight: 700;
|
|
153
|
+
}
|
|
154
|
+
.auth-card small {
|
|
155
|
+
color: var(--muted);
|
|
156
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { headers } from "next/headers";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import "@codelitdev/design-system/styles.css";
|
|
4
|
+
import "./globals.css";
|
|
5
|
+
import { BrowserObservabilityProvider } from "../components/browser-observability";
|
|
6
|
+
import { getBrowserObservabilityConfig } from "../lib/observability-config";
|
|
7
|
+
|
|
8
|
+
export const metadata = {
|
|
9
|
+
title: "Reference product",
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default async function RootLayout({ children }: { children: ReactNode }) {
|
|
13
|
+
await headers();
|
|
14
|
+
const posthog = getBrowserObservabilityConfig();
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<html lang="en">
|
|
18
|
+
<body>
|
|
19
|
+
{posthog ? (
|
|
20
|
+
<BrowserObservabilityProvider
|
|
21
|
+
apiKey={posthog.apiKey}
|
|
22
|
+
host={posthog.host}
|
|
23
|
+
environment={posthog.environment}
|
|
24
|
+
serviceName={posthog.serviceName}
|
|
25
|
+
>
|
|
26
|
+
{children}
|
|
27
|
+
</BrowserObservabilityProvider>
|
|
28
|
+
) : (
|
|
29
|
+
children
|
|
30
|
+
)}
|
|
31
|
+
</body>
|
|
32
|
+
</html>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "@codelitdev/design-system";
|
|
4
|
+
import { type FormEvent, useState } from "react";
|
|
5
|
+
|
|
6
|
+
export default function SignInPage() {
|
|
7
|
+
const [email, setEmail] = useState("");
|
|
8
|
+
const [otp, setOtp] = useState("");
|
|
9
|
+
const [password, setPassword] = useState("");
|
|
10
|
+
const [sent, setSent] = useState(false);
|
|
11
|
+
const [error, setError] = useState<string | null>(null);
|
|
12
|
+
|
|
13
|
+
async function sendCode(event: FormEvent<HTMLFormElement>) {
|
|
14
|
+
event.preventDefault();
|
|
15
|
+
setError(null);
|
|
16
|
+
const response = await fetch("/api/auth/email-otp/send-verification-otp", {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: { "content-type": "application/json" },
|
|
19
|
+
body: JSON.stringify({ email, type: "sign-in" }),
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
setError("Unable to send a sign-in code.");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
setSent(true);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
async function verifyCode(event: FormEvent<HTMLFormElement>) {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
setError(null);
|
|
31
|
+
const response = await fetch("/api/auth/sign-in/email-otp", {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: { "content-type": "application/json" },
|
|
34
|
+
body: JSON.stringify({ email, otp, name: email.split("@")[0] }),
|
|
35
|
+
});
|
|
36
|
+
if (!response.ok) {
|
|
37
|
+
setError("That code is invalid or expired.");
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
window.location.assign("/");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async function signInWithPassword(event: FormEvent<HTMLFormElement>) {
|
|
44
|
+
event.preventDefault();
|
|
45
|
+
setError(null);
|
|
46
|
+
const response = await fetch("/api/auth/sign-in/email", {
|
|
47
|
+
method: "POST",
|
|
48
|
+
headers: { "content-type": "application/json" },
|
|
49
|
+
body: JSON.stringify({ email, password }),
|
|
50
|
+
});
|
|
51
|
+
if (!response.ok) {
|
|
52
|
+
setError("That email or password is invalid.");
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
window.location.assign("/");
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<main className="auth-page">
|
|
60
|
+
<section className="card auth-card stack">
|
|
61
|
+
<p className="eyebrow">CodeLit Platform</p>
|
|
62
|
+
<h1>Sign in</h1>
|
|
63
|
+
<p className="subtitle">Access your reference workspace.</p>
|
|
64
|
+
{!sent ? (
|
|
65
|
+
<form onSubmit={sendCode}>
|
|
66
|
+
<label>
|
|
67
|
+
Email
|
|
68
|
+
<input
|
|
69
|
+
type="email"
|
|
70
|
+
name="email"
|
|
71
|
+
autoComplete="username"
|
|
72
|
+
value={email}
|
|
73
|
+
onChange={(event) => setEmail(event.target.value)}
|
|
74
|
+
required
|
|
75
|
+
/>
|
|
76
|
+
</label>
|
|
77
|
+
<Button type="submit">Send sign-in code</Button>
|
|
78
|
+
</form>
|
|
79
|
+
) : (
|
|
80
|
+
<form onSubmit={verifyCode}>
|
|
81
|
+
<p>Enter the code sent to {email}.</p>
|
|
82
|
+
<label>
|
|
83
|
+
Sign-in code
|
|
84
|
+
<input
|
|
85
|
+
inputMode="numeric"
|
|
86
|
+
name="otp"
|
|
87
|
+
value={otp}
|
|
88
|
+
onChange={(event) => setOtp(event.target.value)}
|
|
89
|
+
required
|
|
90
|
+
/>
|
|
91
|
+
</label>
|
|
92
|
+
<Button type="submit">Sign in</Button>
|
|
93
|
+
</form>
|
|
94
|
+
)}
|
|
95
|
+
{error ? <p role="alert">{error}</p> : null}
|
|
96
|
+
<details>
|
|
97
|
+
<summary>Local demo password sign-in</summary>
|
|
98
|
+
<p>
|
|
99
|
+
When started with SEED=1, use owner@example.com and reference-password-1.
|
|
100
|
+
</p>
|
|
101
|
+
<form onSubmit={signInWithPassword}>
|
|
102
|
+
<label>
|
|
103
|
+
Email
|
|
104
|
+
<input
|
|
105
|
+
type="email"
|
|
106
|
+
value={email}
|
|
107
|
+
onChange={(event) => setEmail(event.target.value)}
|
|
108
|
+
required
|
|
109
|
+
/>
|
|
110
|
+
</label>
|
|
111
|
+
<label>
|
|
112
|
+
Password
|
|
113
|
+
<input
|
|
114
|
+
type="password"
|
|
115
|
+
value={password}
|
|
116
|
+
onChange={(event) => setPassword(event.target.value)}
|
|
117
|
+
required
|
|
118
|
+
/>
|
|
119
|
+
</label>
|
|
120
|
+
<Button type="submit">Sign in with password</Button>
|
|
121
|
+
</form>
|
|
122
|
+
</details>
|
|
123
|
+
<small>Same-origin BFF cookies are set by the API after verification.</small>
|
|
124
|
+
</section>
|
|
125
|
+
</main>
|
|
126
|
+
);
|
|
127
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "@codelitdev/design-system";
|
|
4
|
+
import Link from "next/link";
|
|
5
|
+
import { type FormEvent, useEffect, useState } from "react";
|
|
6
|
+
import { AuthGate } from "../../components/auth-gate";
|
|
7
|
+
|
|
8
|
+
type Note = { id: string; title: string; body: string };
|
|
9
|
+
|
|
10
|
+
export default function NotesPage() {
|
|
11
|
+
const [notes, setNotes] = useState<Note[]>([]);
|
|
12
|
+
const [workspace, setWorkspace] = useState<string | null>(null);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
void fetch("/api/v1/tenants", { credentials: "include", cache: "no-store" })
|
|
15
|
+
.then((response) => (response.ok ? response.json() : { items: [] }))
|
|
16
|
+
.then(
|
|
17
|
+
async (body: {
|
|
18
|
+
items?: { id: string; name: string; selected?: boolean }[];
|
|
19
|
+
}) => {
|
|
20
|
+
const selected = body.items?.find((tenant) => tenant.selected);
|
|
21
|
+
setWorkspace(selected?.name ?? null);
|
|
22
|
+
if (!selected) return { items: [] };
|
|
23
|
+
const response = await fetch("/api/v1/notes", {
|
|
24
|
+
credentials: "include",
|
|
25
|
+
cache: "no-store",
|
|
26
|
+
headers: { "x-tenant-id": selected.id },
|
|
27
|
+
});
|
|
28
|
+
return response.ok ? response.json() : { items: [] };
|
|
29
|
+
},
|
|
30
|
+
)
|
|
31
|
+
.then((body: { items?: Note[] }) => setNotes(body.items ?? []))
|
|
32
|
+
.catch(() => setNotes([]));
|
|
33
|
+
}, []);
|
|
34
|
+
async function create(event: FormEvent<HTMLFormElement>) {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
const formElement = event.currentTarget;
|
|
37
|
+
const form = new FormData(formElement);
|
|
38
|
+
const response = await fetch("/api/v1/notes", {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: { "content-type": "application/json" },
|
|
41
|
+
credentials: "include",
|
|
42
|
+
body: JSON.stringify({
|
|
43
|
+
title: form.get("title"),
|
|
44
|
+
body: form.get("body") ?? "",
|
|
45
|
+
}),
|
|
46
|
+
});
|
|
47
|
+
if (response.ok) {
|
|
48
|
+
const note = (await response.json()) as Note;
|
|
49
|
+
setNotes((current) => [...current, note]);
|
|
50
|
+
formElement.reset();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return (
|
|
54
|
+
<AuthGate>
|
|
55
|
+
<main className="page-shell">
|
|
56
|
+
<header className="app-header">
|
|
57
|
+
<div>
|
|
58
|
+
<p className="eyebrow">Workspace</p>
|
|
59
|
+
<h1>Notes</h1>
|
|
60
|
+
<p className="subtitle">Keep shared notes for your selected workspace.</p>
|
|
61
|
+
<p className="eyebrow">Active workspace: {workspace ?? "None selected"}</p>
|
|
62
|
+
</div>
|
|
63
|
+
<Link href="/">Back to workspace</Link>
|
|
64
|
+
</header>
|
|
65
|
+
<section className="card stack">
|
|
66
|
+
<ul className="note-list">
|
|
67
|
+
{notes.map((note) => (
|
|
68
|
+
<li className="note-item" key={note.id}>
|
|
69
|
+
<strong>{note.title}</strong>
|
|
70
|
+
<span className="muted">{note.body || "No details"}</span>
|
|
71
|
+
</li>
|
|
72
|
+
))}
|
|
73
|
+
{!notes.length ? <li className="muted">No notes yet.</li> : null}
|
|
74
|
+
</ul>
|
|
75
|
+
</section>
|
|
76
|
+
<section className="card stack">
|
|
77
|
+
<h2>Create a note</h2>
|
|
78
|
+
<form onSubmit={create}>
|
|
79
|
+
<label className="field">
|
|
80
|
+
Title
|
|
81
|
+
<input name="title" required />
|
|
82
|
+
</label>
|
|
83
|
+
<label className="field">
|
|
84
|
+
Body
|
|
85
|
+
<textarea name="body" />
|
|
86
|
+
</label>
|
|
87
|
+
<Button type="submit">Create note</Button>
|
|
88
|
+
</form>
|
|
89
|
+
</section>
|
|
90
|
+
</main>
|
|
91
|
+
</AuthGate>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "@codelitdev/design-system";
|
|
4
|
+
import { type FormEvent, useEffect, useState } from "react";
|
|
5
|
+
import { AuthGate } from "../components/auth-gate";
|
|
6
|
+
import { TenantSwitcher } from "../components/tenant-switcher";
|
|
7
|
+
|
|
8
|
+
export default function HomePage() {
|
|
9
|
+
const [tenants, setTenants] = useState<
|
|
10
|
+
{ id: string; name: string; selected?: boolean }[]
|
|
11
|
+
>([]);
|
|
12
|
+
const [error, setError] = useState<string | null>(null);
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
void fetch("/api/v1/tenants", {
|
|
15
|
+
credentials: "include",
|
|
16
|
+
cache: "no-store",
|
|
17
|
+
})
|
|
18
|
+
.then((response) => (response.ok ? response.json() : { items: [] }))
|
|
19
|
+
.then((body: { items?: { id: string; name: string; selected?: boolean }[] }) =>
|
|
20
|
+
setTenants(body.items ?? []),
|
|
21
|
+
)
|
|
22
|
+
.catch(() => setTenants([]));
|
|
23
|
+
}, []);
|
|
24
|
+
async function createTenant(event: FormEvent<HTMLFormElement>) {
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
setError(null);
|
|
27
|
+
const formElement = event.currentTarget;
|
|
28
|
+
const form = new FormData(formElement);
|
|
29
|
+
const response = await fetch("/api/v1/tenants", {
|
|
30
|
+
method: "POST",
|
|
31
|
+
headers: { "content-type": "application/json" },
|
|
32
|
+
credentials: "include",
|
|
33
|
+
body: JSON.stringify({ name: form.get("name") }),
|
|
34
|
+
});
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
setError("Unable to create the tenant.");
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
const tenant = (await response.json()) as {
|
|
40
|
+
id: string;
|
|
41
|
+
name: string;
|
|
42
|
+
selected?: boolean;
|
|
43
|
+
};
|
|
44
|
+
setTenants((current) => [...current, tenant]);
|
|
45
|
+
formElement.reset();
|
|
46
|
+
window.location.reload();
|
|
47
|
+
}
|
|
48
|
+
return (
|
|
49
|
+
<AuthGate>
|
|
50
|
+
<main className="page-shell">
|
|
51
|
+
<header className="app-header">
|
|
52
|
+
<div>
|
|
53
|
+
<p className="eyebrow">CodeLit Platform</p>
|
|
54
|
+
<h1>Reference workspace</h1>
|
|
55
|
+
<p className="subtitle">Manage your teams and shared notes.</p>
|
|
56
|
+
</div>
|
|
57
|
+
</header>
|
|
58
|
+
<section className="card stack" aria-labelledby="tenants-heading">
|
|
59
|
+
<h2 id="tenants-heading">Tenants</h2>
|
|
60
|
+
<TenantSwitcher tenants={tenants} />
|
|
61
|
+
<form onSubmit={createTenant}>
|
|
62
|
+
<label className="field">
|
|
63
|
+
New tenant
|
|
64
|
+
<input name="name" required maxLength={200} />
|
|
65
|
+
</label>
|
|
66
|
+
<Button type="submit">Create tenant</Button>
|
|
67
|
+
</form>
|
|
68
|
+
{error ? <p role="alert">{error}</p> : null}
|
|
69
|
+
</section>
|
|
70
|
+
<section className="card">
|
|
71
|
+
<h2>Notes</h2>
|
|
72
|
+
<p className="subtitle">Create and review notes for the selected tenant.</p>
|
|
73
|
+
<p>
|
|
74
|
+
<a href="/notes">Open notes →</a>
|
|
75
|
+
</p>
|
|
76
|
+
</section>
|
|
77
|
+
</main>
|
|
78
|
+
</AuthGate>
|
|
79
|
+
);
|
|
80
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { type ReactNode, useEffect, useState } from "react";
|
|
4
|
+
|
|
5
|
+
export function AuthGate({ children }: { children: ReactNode }) {
|
|
6
|
+
const [checking, setChecking] = useState(true);
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
let active = true;
|
|
9
|
+
void fetch("/api/auth/get-session", {
|
|
10
|
+
cache: "no-store",
|
|
11
|
+
credentials: "include",
|
|
12
|
+
})
|
|
13
|
+
.then(async (response) => {
|
|
14
|
+
if (!response.ok) return false;
|
|
15
|
+
const body = (await response.json()) as { user?: unknown };
|
|
16
|
+
return Boolean(body.user);
|
|
17
|
+
})
|
|
18
|
+
.catch(() => false)
|
|
19
|
+
.then((authenticated) => {
|
|
20
|
+
if (!active) return;
|
|
21
|
+
if (!authenticated) {
|
|
22
|
+
window.location.replace("/login");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
setChecking(false);
|
|
26
|
+
});
|
|
27
|
+
return () => {
|
|
28
|
+
active = false;
|
|
29
|
+
};
|
|
30
|
+
}, []);
|
|
31
|
+
|
|
32
|
+
if (checking) return <main>Checking session…</main>;
|
|
33
|
+
return children;
|
|
34
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { createBrowserObservability } from "@codelitdev/observability/browser";
|
|
4
|
+
import { type ReactNode, useEffect } from "react";
|
|
5
|
+
|
|
6
|
+
export function BrowserObservabilityProvider({
|
|
7
|
+
apiKey,
|
|
8
|
+
host,
|
|
9
|
+
environment,
|
|
10
|
+
serviceName,
|
|
11
|
+
children,
|
|
12
|
+
}: {
|
|
13
|
+
apiKey: string;
|
|
14
|
+
host?: string;
|
|
15
|
+
environment: string;
|
|
16
|
+
serviceName: string;
|
|
17
|
+
children: ReactNode;
|
|
18
|
+
}) {
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
const observability = createBrowserObservability({
|
|
21
|
+
apiKey,
|
|
22
|
+
host,
|
|
23
|
+
environment,
|
|
24
|
+
serviceName,
|
|
25
|
+
});
|
|
26
|
+
void observability.init().then(async () => {
|
|
27
|
+
if (!observability.enabled) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const response = await fetch("/api/auth/get-session", {
|
|
32
|
+
cache: "no-store",
|
|
33
|
+
credentials: "include",
|
|
34
|
+
});
|
|
35
|
+
if (!response.ok) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const session = (await response.json()) as {
|
|
39
|
+
user?: {
|
|
40
|
+
id?: string;
|
|
41
|
+
email?: string;
|
|
42
|
+
name?: string | null;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
observability.identify(session.user);
|
|
46
|
+
} catch {
|
|
47
|
+
// Telemetry must not break the admin shell.
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
}, [apiKey, host, environment, serviceName]);
|
|
51
|
+
|
|
52
|
+
return children;
|
|
53
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Button } from "@codelitdev/design-system";
|
|
4
|
+
import { type FormEvent, useState } from "react";
|
|
5
|
+
|
|
6
|
+
type Tenant = { id: string; name: string; selected?: boolean };
|
|
7
|
+
|
|
8
|
+
export function TenantSwitcher({ tenants }: { tenants: Tenant[] }) {
|
|
9
|
+
const [error, setError] = useState<string | null>(null);
|
|
10
|
+
const selectedId = tenants.find((tenant) => tenant.selected)?.id ?? "";
|
|
11
|
+
async function switchTenant(event: FormEvent<HTMLFormElement>) {
|
|
12
|
+
event.preventDefault();
|
|
13
|
+
setError(null);
|
|
14
|
+
const form = new FormData(event.currentTarget);
|
|
15
|
+
const response = await fetch("/api/tenant/select", {
|
|
16
|
+
method: "POST",
|
|
17
|
+
headers: { "content-type": "application/json" },
|
|
18
|
+
credentials: "include",
|
|
19
|
+
body: JSON.stringify({ tenantId: form.get("tenantId") }),
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) {
|
|
22
|
+
const payload = (await response.json().catch(() => null)) as {
|
|
23
|
+
message?: string;
|
|
24
|
+
} | null;
|
|
25
|
+
setError(payload?.message ?? `Unable to switch tenant (${response.status}).`);
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
window.location.reload();
|
|
29
|
+
}
|
|
30
|
+
return (
|
|
31
|
+
<form onSubmit={switchTenant}>
|
|
32
|
+
<label className="field">
|
|
33
|
+
Tenant
|
|
34
|
+
<select
|
|
35
|
+
key={selectedId}
|
|
36
|
+
name="tenantId"
|
|
37
|
+
aria-label="Tenant switcher"
|
|
38
|
+
defaultValue={selectedId}
|
|
39
|
+
>
|
|
40
|
+
{tenants.map((tenant) => (
|
|
41
|
+
<option key={tenant.id} value={tenant.id}>
|
|
42
|
+
{tenant.name}
|
|
43
|
+
</option>
|
|
44
|
+
))}
|
|
45
|
+
</select>
|
|
46
|
+
</label>
|
|
47
|
+
<Button type="submit">Switch tenant</Button>
|
|
48
|
+
{error ? <span role="alert">{error}</span> : null}
|
|
49
|
+
</form>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** Request-time PostHog config. Do not use `NEXT_PUBLIC_*` — those freeze at
|
|
2
|
+
* `next build`. Missing `POSTHOG_API_KEY` disables browser telemetry. */
|
|
3
|
+
export function getBrowserObservabilityConfig() {
|
|
4
|
+
const apiKey = process.env.POSTHOG_API_KEY?.trim() || null;
|
|
5
|
+
if (!apiKey) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
apiKey,
|
|
11
|
+
host: process.env.POSTHOG_HOST?.trim() || undefined,
|
|
12
|
+
environment: process.env.DEPLOY_ENV || process.env.NODE_ENV || "unknown",
|
|
13
|
+
serviceName: "__PRODUCT_SLUG__-web",
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@__PRODUCT_SLUG__/web",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "next dev",
|
|
8
|
+
"build": "next build",
|
|
9
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
10
|
+
"start": "next start"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@codelitdev/design-system": "workspace:*",
|
|
14
|
+
"@codelitdev/observability": "workspace:*",
|
|
15
|
+
"next": "^15.5.4",
|
|
16
|
+
"posthog-js": "^1.425.1",
|
|
17
|
+
"react": "^19.1.1",
|
|
18
|
+
"react-dom": "^19.1.1"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^22.14.1",
|
|
22
|
+
"@types/react": "^19.1.13",
|
|
23
|
+
"@types/react-dom": "^19.1.9",
|
|
24
|
+
"typescript": "^5.9.3"
|
|
25
|
+
}
|
|
26
|
+
}
|