create-feltkit 0.3.18 → 0.3.20
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 +6 -0
- package/bin/create.js +93 -9
- package/package.json +6 -2
- package/scaffold.d.ts +2 -2
- package/scaffold.js +4 -1
- package/template/package.json +1 -1
- package/template-foundation/README.md +24 -0
- package/template-foundation/_gitignore +12 -0
- package/template-foundation/feltkit/_generated/api.ts +7 -0
- package/template-foundation/feltkit/app.ts +11 -0
- package/template-foundation/index.html +15 -0
- package/template-foundation/package.json +31 -0
- package/template-foundation/public/apple-touch-icon.png +0 -0
- package/template-foundation/public/favicon.png +0 -0
- package/template-foundation/src/App.tsx +60 -0
- package/template-foundation/src/main.tsx +17 -0
- package/template-foundation/src/styles.css +38 -0
- package/template-foundation/tests/foundation.test.ts +24 -0
- package/template-foundation/tsconfig.json +16 -0
- package/template-foundation/vite.config.ts +6 -0
- package/template-managed/feltdb.contract.json +776 -23
- package/template-managed/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
<p align="center">
|
|
2
|
+
|
|
3
|
+
> **Three starters.** `tasks` and `managed` are copied from `examples/tasks` and `examples/managed` by
|
|
4
|
+
> `sync-template.mjs`. `foundation` (`template-foundation/`) is the shell `npx feltkit create` composes
|
|
5
|
+
> into: FeltKit's sign-in, invitation, workspace and account screens, a placeholder `feltkit/app.ts` the
|
|
6
|
+
> composer replaces with yours, one foundation test, and no domain of its own. It is maintained here, by
|
|
7
|
+
> hand; the composer fills it in from your selections and generates the foundation with `feltkit compose`.
|
|
2
8
|
<picture>
|
|
3
9
|
<source media="(prefers-color-scheme: dark)" srcset="https://cdn.jsdelivr.net/npm/@feltdb/feltkit/docs/assets/feltkit-logo-dark.png">
|
|
4
10
|
<img src="https://cdn.jsdelivr.net/npm/@feltdb/feltkit/docs/assets/feltkit-logo.png" alt="FeltKit" width="160">
|
package/bin/create.js
CHANGED
|
@@ -1,21 +1,47 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
// npm create feltkit@latest <dir>
|
|
3
|
-
|
|
2
|
+
// npm create feltkit@latest <dir> the application-composition interview (the default)
|
|
3
|
+
// npm create feltkit@latest <dir> -- --template <t> a fixed starter, unchanged
|
|
4
|
+
//
|
|
5
|
+
// Two jobs, one of each. The composition interview and the composition pipeline live in `@feltdb/feltkit`; this
|
|
6
|
+
// bootstrapper runs that binary rather than reimplementing any part of it, so there is exactly one interview and one
|
|
7
|
+
// pipeline. The starters it used to be only about are still here, now asked for explicitly with `--template`.
|
|
8
|
+
//
|
|
9
|
+
// Why it runs the composer's binary instead of importing it: `@feltdb/feltkit` does not export its CLI (its public
|
|
10
|
+
// exports are the runtime, not `createCommand`), and a wrapper must not reach past a package's export map. Running
|
|
11
|
+
// the binary also hands the terminal, the signals and the exit code to the composer unchanged, which is what a
|
|
12
|
+
// developer answering questions needs. The binary comes from the declared dependency on disk; nothing is downloaded
|
|
13
|
+
// or installed when this runs.
|
|
14
|
+
import { spawnSync } from "node:child_process";
|
|
15
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
16
|
+
import { dirname, join, resolve } from "node:path";
|
|
17
|
+
import { fileURLToPath } from "node:url";
|
|
18
|
+
|
|
4
19
|
import { scaffold, TEMPLATES, VERSION } from "../scaffold.js";
|
|
5
20
|
|
|
6
|
-
|
|
21
|
+
// `npm create feltkit <dir> -- --flag` has npm remove the `--` before this runs, but a direct
|
|
22
|
+
// `create-feltkit <dir> -- --flag` does not, and the composer would then read `--` as an argument and miss the flags
|
|
23
|
+
// after it. Dropping a standalone separator makes both spellings mean the same thing.
|
|
24
|
+
const args = process.argv.slice(2).filter((a) => a !== "--");
|
|
7
25
|
const color = process.stdout.isTTY && !process.env.NO_COLOR;
|
|
8
26
|
const bold = (s) => (color ? `\u001b[1m${s}\u001b[22m` : s);
|
|
9
27
|
const dim = (s) => (color ? `\u001b[2m${s}\u001b[22m` : s);
|
|
10
28
|
const green = (s) => (color ? `\u001b[32m${s}\u001b[39m` : s);
|
|
11
29
|
const red = (s) => (color ? `\u001b[31m${s}\u001b[39m` : s);
|
|
12
30
|
|
|
31
|
+
const COMPOSER = "@feltdb/feltkit";
|
|
32
|
+
|
|
13
33
|
if (args.includes("--help") || args.includes("-h")) {
|
|
14
|
-
console.log(`npm create feltkit@latest <directory>
|
|
34
|
+
console.log(`npm create feltkit@latest <directory>
|
|
15
35
|
|
|
16
|
-
|
|
36
|
+
Composes a FeltKit application: it asks what kind of application you are building, who the data belongs to,
|
|
37
|
+
who uses it and which capabilities it needs, then generates the foundation from your answers.
|
|
38
|
+
Every \`feltkit create\` flag works here too; pass them after \`--\`.
|
|
17
39
|
|
|
18
|
-
|
|
40
|
+
npm create feltkit@latest my-app
|
|
41
|
+
npm create feltkit@latest my-app -- --yes --data-belongs-to individuals (no questions)
|
|
42
|
+
npm create feltkit@latest my-app -- --help (every composition flag)
|
|
43
|
+
|
|
44
|
+
Starters instead of composing (--template), each a complete application you can run immediately:
|
|
19
45
|
${Object.entries(TEMPLATES).map(([name, { description }]) => ` ${name.padEnd(9)}${description}`).join("\n")}
|
|
20
46
|
|
|
21
47
|
--managed is short for --template managed.`);
|
|
@@ -25,15 +51,73 @@ if (args.includes("--version")) {
|
|
|
25
51
|
console.log(VERSION);
|
|
26
52
|
process.exit(0);
|
|
27
53
|
}
|
|
54
|
+
|
|
28
55
|
const VALUE_FLAGS = ["--name", "--template"];
|
|
29
56
|
const valueOf = (flag) => {
|
|
30
57
|
const index = args.indexOf(flag);
|
|
31
58
|
return index >= 0 ? args[index + 1] : undefined;
|
|
32
59
|
};
|
|
33
|
-
const name = valueOf("--name");
|
|
34
|
-
const template = args.includes("--managed") ? "managed" : (valueOf("--template") ?? "tasks");
|
|
35
|
-
const dir = args.find((a, i) => !a.startsWith("-") && !VALUE_FLAGS.includes(args[i - 1])) ?? "my-feltkit-app";
|
|
36
60
|
|
|
61
|
+
/**
|
|
62
|
+
* The composer's executable, from this package's declared dependency.
|
|
63
|
+
*
|
|
64
|
+
* Resolved by walking up from the dependency's own entry point to the directory that holds its `package.json`, which
|
|
65
|
+
* works whatever the package's export map allows: `require.resolve("<pkg>/package.json")` throws for a package whose
|
|
66
|
+
* exports do not list it, and most now do not.
|
|
67
|
+
*/
|
|
68
|
+
function composerBin() {
|
|
69
|
+
let from;
|
|
70
|
+
try {
|
|
71
|
+
from = fileURLToPath(import.meta.resolve(COMPOSER));
|
|
72
|
+
} catch {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
for (let dir = dirname(from); ; dir = dirname(dir)) {
|
|
76
|
+
const manifest = join(dir, "package.json");
|
|
77
|
+
if (existsSync(manifest)) {
|
|
78
|
+
try {
|
|
79
|
+
if (JSON.parse(readFileSync(manifest, "utf8")).name === COMPOSER) {
|
|
80
|
+
const bin = join(dir, "bin", "feltkit.js");
|
|
81
|
+
return existsSync(bin) ? bin : null;
|
|
82
|
+
}
|
|
83
|
+
} catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (dirname(dir) === dir) return null;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const template = args.includes("--managed") ? "managed" : valueOf("--template");
|
|
92
|
+
// The destination is the first argument that is neither a flag nor a flag's value. Its index is kept so only that
|
|
93
|
+
// one argument is replaced when the rest is forwarded: a `--name my-app` whose value happens to equal the directory
|
|
94
|
+
// must survive.
|
|
95
|
+
const dirIndex = args.findIndex((a, i) => !a.startsWith("-") && !VALUE_FLAGS.includes(args[i - 1]));
|
|
96
|
+
const dir = dirIndex >= 0 ? args[dirIndex] : "my-feltkit-app";
|
|
97
|
+
|
|
98
|
+
if (!template) {
|
|
99
|
+
// The default: compose. Everything after the directory is the composer's to interpret, so a flag added to
|
|
100
|
+
// `feltkit create` works here the day it ships, without this file knowing about it.
|
|
101
|
+
const bin = composerBin();
|
|
102
|
+
if (!bin) {
|
|
103
|
+
console.error(`${red("✗")} ${COMPOSER} is not installed beside this package, so the composition interview cannot be started.`);
|
|
104
|
+
console.error(` hint: run \`npm create feltkit@latest ${dir}\` again (npm installs this package's dependencies), or scaffold a starter instead: \`npm create feltkit@latest ${dir} -- --template tasks\``);
|
|
105
|
+
process.exit(1);
|
|
106
|
+
}
|
|
107
|
+
const forwarded = args.filter((_, i) => i !== dirIndex);
|
|
108
|
+
const result = spawnSync(process.execPath, [bin, "create", dir, ...forwarded], { stdio: "inherit" });
|
|
109
|
+
// The composer owns the outcome: its exit code, and a signal that stopped it, pass through unchanged so a
|
|
110
|
+
// cancelled interview is a cancelled command here too.
|
|
111
|
+
if (result.error) {
|
|
112
|
+
console.error(`${red("✗")} could not start the composition interview: ${result.error.message}`);
|
|
113
|
+
process.exit(1);
|
|
114
|
+
}
|
|
115
|
+
if (result.signal) process.kill(process.pid, result.signal);
|
|
116
|
+
process.exit(result.status ?? 1);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// A starter, asked for explicitly. Unchanged behaviour, including every message.
|
|
120
|
+
const name = valueOf("--name");
|
|
37
121
|
try {
|
|
38
122
|
const result = scaffold({ target: resolve(process.cwd(), dir), template, ...(name ? { name } : {}) });
|
|
39
123
|
console.log(`${green("✓")} Created ${bold(result.name)} in ${result.dir}${template === "tasks" ? "" : ` (${template} starter)`}\n`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-feltkit",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.20",
|
|
4
4
|
"description": "Create a FeltKit application: npm create feltkit@latest my-app (add -- --template managed for Managed FeltDB)",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"scaffold.d.ts",
|
|
28
28
|
"template",
|
|
29
29
|
"template-managed",
|
|
30
|
+
"template-foundation",
|
|
30
31
|
"README.md"
|
|
31
32
|
],
|
|
32
33
|
"scripts": {
|
|
@@ -34,5 +35,8 @@
|
|
|
34
35
|
"prepack": "node sync-template.mjs",
|
|
35
36
|
"test": "node --test test/*.test.mjs"
|
|
36
37
|
},
|
|
37
|
-
"homepage": "https://www.npmjs.com/package/create-feltkit"
|
|
38
|
+
"homepage": "https://www.npmjs.com/package/create-feltkit",
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@feltdb/feltkit": "0.3.20"
|
|
41
|
+
}
|
|
38
42
|
}
|
package/scaffold.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type TemplateName = "tasks" | "managed";
|
|
1
|
+
export type TemplateName = "tasks" | "managed" | "foundation";
|
|
2
2
|
export interface ScaffoldOptions {
|
|
3
3
|
/** Directory to create. Must not exist or be empty. */
|
|
4
4
|
target: string;
|
|
@@ -6,7 +6,7 @@ export interface ScaffoldOptions {
|
|
|
6
6
|
name?: string;
|
|
7
7
|
/** Version spec for feltkit; defaults to this package's version (released in lockstep). */
|
|
8
8
|
sdkSpec?: string;
|
|
9
|
-
/** Which starter: `tasks` (default, local FeltDB)
|
|
9
|
+
/** Which starter: `tasks` (default, local FeltDB), `managed` (Managed FeltDB), or `foundation` (the shell `feltkit create` composes into). */
|
|
10
10
|
template?: TemplateName;
|
|
11
11
|
}
|
|
12
12
|
export interface ScaffoldResult {
|
package/scaffold.js
CHANGED
|
@@ -6,7 +6,9 @@ import { fileURLToPath } from "node:url";
|
|
|
6
6
|
export const VERSION = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")).version;
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* The starters.
|
|
9
|
+
* The starters. All are the same FeltKit; they differ in where state lives and how it is deployed.
|
|
10
|
+
* foundation the shell `npx feltkit create` composes into: FeltKit's auth and workspace screens, a
|
|
11
|
+
* placeholder feltkit/app.ts that the composer replaces, no domain of its own.
|
|
10
12
|
* tasks a task manager with a React frontend, AppPort Services (files, intelligence) and an agent;
|
|
11
13
|
* state in local FeltDB (`.feltkit/<env>/state`), or a FeltDB server you run.
|
|
12
14
|
* managed an inventory API whose state lives in Managed FeltDB: no AppPort Services (Managed FeltDB
|
|
@@ -16,6 +18,7 @@ export const VERSION = JSON.parse(readFileSync(new URL("./package.json", import.
|
|
|
16
18
|
export const TEMPLATES = Object.freeze({
|
|
17
19
|
tasks: { dir: "template", description: "Task manager with a frontend; local FeltDB (default)" },
|
|
18
20
|
managed: { dir: "template-managed", description: "Inventory API on Managed FeltDB; contract, keys and deployment as code" },
|
|
21
|
+
foundation: { dir: "template-foundation", description: "A composed foundation (accounts, workspaces when the data belongs to organizations, your capabilities); `npx feltkit create` fills it in" },
|
|
19
22
|
});
|
|
20
23
|
|
|
21
24
|
export class ScaffoldError extends Error {
|
package/template/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# foundation
|
|
2
|
+
|
|
3
|
+
A FeltKit application composed with `npx feltkit create`. Its foundation (accounts, workspaces, roles,
|
|
4
|
+
invitations, and the capabilities you selected) is generated into `feltkit/_foundation/declaration.ts`
|
|
5
|
+
from `feltkit.composition.json`; `feltkit/app.ts` imports it and adds what is yours: your data, your
|
|
6
|
+
functions, your permissions on them.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install
|
|
10
|
+
npm run dev # backend, frontend and dashboard with hot reload
|
|
11
|
+
npm test # the foundation tests, and yours
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
Composition:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx feltkit compose --check # the generated foundation is what the record says
|
|
18
|
+
npx feltkit compose reconcile # how the foundation relates to feltkit/app.ts
|
|
19
|
+
npx feltkit compose plan --include <cap> # what adding a capability would change
|
|
20
|
+
npx feltkit compose apply … --approve <id> # apply exactly that plan
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Do not edit the three generated files (`feltkit/_foundation/declaration.ts`, `feltkit.composition.json`,
|
|
24
|
+
`feltkit.composition.lock.json`); change the composition with `feltkit compose`. Everything else is yours.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
node_modules/
|
|
2
|
+
dist/
|
|
3
|
+
.feltkit/
|
|
4
|
+
.feltkit-platform/
|
|
5
|
+
# Credentials and local deployment state: environment files (FELTKIT_*, FELTDB_* keys), and what
|
|
6
|
+
# `feltdb init-managed` / `feltdb managed keys` write if this app later moves to Managed FeltDB.
|
|
7
|
+
# Never commit.
|
|
8
|
+
.env
|
|
9
|
+
.env.*
|
|
10
|
+
!.env.example
|
|
11
|
+
.feltdb/
|
|
12
|
+
*.app/
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/* Generated by `feltkit dev` / `feltkit codegen`. Do not edit; it is rewritten when feltkit/ changes. */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import { createApi } from "@feltdb/feltkit/client";
|
|
4
|
+
import type * as app_module from "../app.js";
|
|
5
|
+
|
|
6
|
+
/** Typed references to every query and mutation. Type-only imports: no backend code reaches the browser. */
|
|
7
|
+
export const api = createApi<{ "app": typeof app_module }>();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The application. `feltkit create` replaces this file with the one it composes from your selections:
|
|
3
|
+
* it imports the generated foundation (feltkit/_foundation/declaration.ts) and adds what is yours.
|
|
4
|
+
*/
|
|
5
|
+
import { feltkit } from "@feltdb/feltkit";
|
|
6
|
+
|
|
7
|
+
export const app = feltkit({
|
|
8
|
+
name: "foundation",
|
|
9
|
+
roles: { member: [] },
|
|
10
|
+
auth: { accounts: { roles: ["member"] } },
|
|
11
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<meta name="color-scheme" content="light dark" />
|
|
7
|
+
<link rel="icon" href="/favicon.png" type="image/png" />
|
|
8
|
+
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
|
|
9
|
+
<title>foundation · FeltKit</title>
|
|
10
|
+
</head>
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"></div>
|
|
13
|
+
<script type="module" src="/src/main.tsx"></script>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "feltkit-foundation",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "feltkit dev",
|
|
8
|
+
"build": "feltkit build",
|
|
9
|
+
"start": "feltkit start",
|
|
10
|
+
"test": "feltkit test",
|
|
11
|
+
"inspect": "feltkit inspect",
|
|
12
|
+
"deploy": "feltkit deploy",
|
|
13
|
+
"typecheck": "tsc --noEmit",
|
|
14
|
+
"compose:check": "feltkit compose --check",
|
|
15
|
+
"compose:reconcile": "feltkit compose reconcile",
|
|
16
|
+
"compose:plan": "feltkit compose plan"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@feltdb/feltkit": "0.3.20",
|
|
20
|
+
"react": "19.2.0",
|
|
21
|
+
"react-dom": "19.2.0"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/node": "22.19.1",
|
|
25
|
+
"@types/react": "19.2.2",
|
|
26
|
+
"@types/react-dom": "19.2.2",
|
|
27
|
+
"@vitejs/plugin-react": "5.1.0",
|
|
28
|
+
"typescript": "5.9.3",
|
|
29
|
+
"vite": "7.3.7"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The app shell. Sign-in, invitations, workspaces, members and account settings are FeltKit's
|
|
3
|
+
* components, driven by the foundation `feltkit create` composed; this file only arranges them.
|
|
4
|
+
* Your own screens go where <Home /> is: query and mutate your collections through
|
|
5
|
+
* feltkit/_generated/api (run `npx feltkit codegen` after adding functions under feltkit/).
|
|
6
|
+
*/
|
|
7
|
+
import { useState } from "react";
|
|
8
|
+
import {
|
|
9
|
+
AcceptInvitation, AccountSettings, AuthNotices, CreateTenant, SignIn, TenantSettings, TenantSwitcher, VerifyEmailBanner,
|
|
10
|
+
useAuth, useAuthRedirect, useTenant,
|
|
11
|
+
} from "@feltdb/feltkit/react";
|
|
12
|
+
|
|
13
|
+
type View = "home" | "workspace" | "account";
|
|
14
|
+
const BRAND = "foundation";
|
|
15
|
+
|
|
16
|
+
export function App() {
|
|
17
|
+
const auth = useAuth();
|
|
18
|
+
const tenant = useTenant();
|
|
19
|
+
const { redirect } = useAuthRedirect();
|
|
20
|
+
const [view, setView] = useState<View>("home");
|
|
21
|
+
|
|
22
|
+
if (auth.loading) return <div className="center" aria-busy="true">Loading…</div>;
|
|
23
|
+
if (redirect?.kind === "invitation") return <AcceptInvitation brand={{ name: BRAND }} onAccepted={() => setView("home")} />;
|
|
24
|
+
if (!auth.user) return <SignIn brand={{ name: BRAND, logo: "/favicon.png" }} />;
|
|
25
|
+
if (!tenant.current) return <CreateTenant />;
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<div className="shell">
|
|
29
|
+
<header className="topbar">
|
|
30
|
+
<div className="left">
|
|
31
|
+
<strong className="brand">{BRAND}</strong>
|
|
32
|
+
<TenantSwitcher onSwitched={() => setView("home")} />
|
|
33
|
+
</div>
|
|
34
|
+
<nav aria-label="Main">
|
|
35
|
+
{(["home", "workspace", "account"] as const).map((v) => (
|
|
36
|
+
<button key={v} type="button" className={view === v ? "on" : ""} aria-current={view === v ? "page" : undefined} onClick={() => setView(v)}>
|
|
37
|
+
{v === "home" ? "Home" : v === "workspace" ? "Workspace" : "Account"}
|
|
38
|
+
</button>
|
|
39
|
+
))}
|
|
40
|
+
</nav>
|
|
41
|
+
</header>
|
|
42
|
+
<main>
|
|
43
|
+
<AuthNotices />
|
|
44
|
+
<VerifyEmailBanner />
|
|
45
|
+
{view === "home" && <Home role={tenant.current.role} />}
|
|
46
|
+
{view === "workspace" && <TenantSettings />}
|
|
47
|
+
{view === "account" && <AccountSettings />}
|
|
48
|
+
</main>
|
|
49
|
+
</div>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function Home({ role }: { role: string }) {
|
|
54
|
+
return (
|
|
55
|
+
<section>
|
|
56
|
+
<h1>Welcome</h1>
|
|
57
|
+
<p className="muted">You are a {role} here. Accounts, workspaces, roles and invitations work already; the screens for your own data are yours to build.</p>
|
|
58
|
+
</section>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { StrictMode } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
import { createClient } from "@feltdb/feltkit/client";
|
|
4
|
+
import { FeltKitProvider } from "@feltdb/feltkit/react";
|
|
5
|
+
import { App } from "./App";
|
|
6
|
+
import "./styles.css";
|
|
7
|
+
|
|
8
|
+
// Same origin as the page. In a browser the session is an HttpOnly cookie (never readable by scripts).
|
|
9
|
+
const client = createClient();
|
|
10
|
+
|
|
11
|
+
createRoot(document.getElementById("root")!).render(
|
|
12
|
+
<StrictMode>
|
|
13
|
+
<FeltKitProvider client={client}>
|
|
14
|
+
<App />
|
|
15
|
+
</FeltKitProvider>
|
|
16
|
+
</StrictMode>,
|
|
17
|
+
);
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/* The app's own tokens. FeltKit's components pick them up (--accent, --surface, --ink, --muted, --line, --radius). */
|
|
2
|
+
:root {
|
|
3
|
+
color-scheme: light dark;
|
|
4
|
+
--bg: light-dark(#f6f6f4, #101211);
|
|
5
|
+
--surface: light-dark(#ffffff, #181b1a);
|
|
6
|
+
--ink: light-dark(#1b1d1c, #eceeed);
|
|
7
|
+
--muted: light-dark(#6b706d, #9aa19d);
|
|
8
|
+
--line: light-dark(#e4e5e1, #2a2f2c);
|
|
9
|
+
--accent: light-dark(#4338ca, #a5b4fc);
|
|
10
|
+
--accent-ink: light-dark(#ffffff, #111827);
|
|
11
|
+
--radius: 10px;
|
|
12
|
+
font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
|
13
|
+
background: var(--bg);
|
|
14
|
+
color: var(--ink);
|
|
15
|
+
}
|
|
16
|
+
* { box-sizing: border-box; }
|
|
17
|
+
body { margin: 0; }
|
|
18
|
+
button, input, textarea { font: inherit; color: inherit; }
|
|
19
|
+
.center { display: grid; place-items: center; min-height: 100vh; color: var(--muted); }
|
|
20
|
+
.shell { min-height: 100vh; }
|
|
21
|
+
.topbar { position: sticky; top: 0; z-index: 10; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--line); }
|
|
22
|
+
.topbar .left { display: flex; align-items: center; gap: 12px; min-width: 0; }
|
|
23
|
+
.brand { font-size: 17px; }
|
|
24
|
+
nav { display: flex; gap: 4px; }
|
|
25
|
+
nav button { border: 0; background: transparent; padding: 8px 12px; border-radius: 8px; cursor: pointer; color: var(--muted); }
|
|
26
|
+
nav button.on { background: color-mix(in srgb, var(--accent) 12%, var(--surface)); color: var(--ink); font-weight: 600; }
|
|
27
|
+
main { max-width: 760px; margin: 0 auto; padding: 20px 16px 60px; display: flex; flex-direction: column; gap: 12px; }
|
|
28
|
+
h1 { font-size: 22px; margin: 4px 0 12px; }
|
|
29
|
+
.muted { color: var(--muted); }
|
|
30
|
+
.error { color: #c0262d; }
|
|
31
|
+
.compose { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
|
|
32
|
+
.compose input, .compose textarea { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
|
|
33
|
+
.compose button { align-self: flex-start; padding: 9px 16px; border: 0; border-radius: var(--radius); background: var(--accent); color: var(--accent-ink); font-weight: 600; cursor: pointer; }
|
|
34
|
+
.list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
|
|
35
|
+
.list li { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
|
|
36
|
+
.list p { margin: 4px 0; white-space: pre-wrap; }
|
|
37
|
+
.ghost { border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 4px 10px; cursor: pointer; height: fit-content; }
|
|
38
|
+
@media (max-width: 560px) { .topbar { padding: 8px 12px; } nav button { padding: 6px 8px; } }
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The composed foundation, as executable guarantees: accounts exist, a workspace can be created and
|
|
3
|
+
* its members hold the roles the composition declared. Add your own tests beside this one.
|
|
4
|
+
* Run with `npm test` (`feltkit test`).
|
|
5
|
+
*/
|
|
6
|
+
import { test } from "node:test";
|
|
7
|
+
import assert from "node:assert/strict";
|
|
8
|
+
import { createTestApp } from "@feltdb/feltkit/testing";
|
|
9
|
+
|
|
10
|
+
test("the foundation: accounts, a workspace, and its declared roles", async () => {
|
|
11
|
+
const t = await createTestApp();
|
|
12
|
+
try {
|
|
13
|
+
const runtime = t.runtime;
|
|
14
|
+
assert.ok(runtime.accounts, "accounts are part of the foundation");
|
|
15
|
+
const created = await runtime.accounts!.signUp({ email: "owner@example.com", password: "a-long-password-1", name: "Owner" });
|
|
16
|
+
await runtime.accounts!.markVerified(created.id);
|
|
17
|
+
assert.ok(t.tenancy, "workspaces are part of the foundation");
|
|
18
|
+
const options = runtime.project.app.options as unknown as { roles: Record<string, string[]>; auth: { tenant: { roles: string[] } } };
|
|
19
|
+
assert.ok(options.auth.tenant.roles.length > 0, "the workspace declares its roles");
|
|
20
|
+
for (const role of options.auth.tenant.roles) assert.ok(role in options.roles, `role ${role} is declared`);
|
|
21
|
+
} finally {
|
|
22
|
+
await t.close();
|
|
23
|
+
}
|
|
24
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "Bundler",
|
|
6
|
+
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noEmit": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"verbatimModuleSyntax": true,
|
|
13
|
+
"types": ["node", "vite/client"]
|
|
14
|
+
},
|
|
15
|
+
"include": ["src", "feltkit", "tests", "vite.config.ts"]
|
|
16
|
+
}
|