create-user-hub 0.0.0-stage → 0.1.3

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.
Files changed (42) hide show
  1. package/README.md +26 -2
  2. package/index.js +192 -0
  3. package/package.json +12 -4
  4. package/template/.env.example +7 -0
  5. package/template/CLAUDE.md +24 -0
  6. package/template/README.md +29 -0
  7. package/template/biome.json +46 -0
  8. package/template/components.json +25 -0
  9. package/template/convex/_generated/api.ts +56 -0
  10. package/template/convex/_generated/dataModel.ts +60 -0
  11. package/template/convex/_generated/server.ts +175 -0
  12. package/template/convex/auth.config.ts +7 -0
  13. package/template/convex/hub.ts +2 -0
  14. package/template/convex/me.ts +18 -0
  15. package/template/convex/model/notes.ts +25 -0
  16. package/template/convex/notes.ts +41 -0
  17. package/template/convex/schema.ts +10 -0
  18. package/template/convex/tsconfig.json +26 -0
  19. package/template/convex.json +9 -0
  20. package/template/gitignore +11 -0
  21. package/template/package.json +41 -0
  22. package/template/scripts/setup.ts +216 -0
  23. package/template/server.ts +50 -0
  24. package/template/src/components/ui/badge.tsx +51 -0
  25. package/template/src/components/ui/button.tsx +55 -0
  26. package/template/src/components/ui/card.tsx +99 -0
  27. package/template/src/components/ui/empty.tsx +103 -0
  28. package/template/src/components/ui/field.tsx +236 -0
  29. package/template/src/components/ui/input.tsx +19 -0
  30. package/template/src/components/ui/item.tsx +201 -0
  31. package/template/src/components/ui/label.tsx +17 -0
  32. package/template/src/components/ui/separator.tsx +22 -0
  33. package/template/src/components/ui/skeleton.tsx +13 -0
  34. package/template/src/lib/utils.ts +1 -0
  35. package/template/src/routeTree.gen.ts +86 -0
  36. package/template/src/router.tsx +16 -0
  37. package/template/src/routes/__root.tsx +81 -0
  38. package/template/src/routes/facilitator.tsx +100 -0
  39. package/template/src/routes/index.tsx +142 -0
  40. package/template/src/styles.css +137 -0
  41. package/template/tsconfig.json +27 -0
  42. package/template/vite.config.ts +15 -0
package/README.md CHANGED
@@ -1,3 +1,27 @@
1
- # Temporary Holding Version
1
+ # create-user-hub
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ > **Private beta.** This starter needs a User Hub, which is not public yet. Until then it is only useful to teams already running one.
4
+
5
+ Start a new app with User Hub sign-in already wired: people scan their badge and arrive signed in.
6
+
7
+ ```sh
8
+ bun create user-hub@latest my-app
9
+ ```
10
+
11
+ It asks for your hub's URL and admin password (from your hub's admin; the password shows as stars), checks the hub answers and saves both to the app's `.env.local`.
12
+
13
+ Scripts and coding agents are never asked when `HUB_URL` and `HUB_ADMIN_PASSWORD` are already in the environment (for example through your secret manager). The password is never a command-line flag, so it stays out of shell history.
14
+
15
+ You get a TanStack Start + Convex app with Tailwind, shadcn (dark theme) and Biome, plus:
16
+
17
+ - **Sign-in** from [`@user-hub/auth`](https://www.npmjs.com/package/@user-hub/auth): a signed-in home page, a facilitator-only page, sign-out, and notes saved per person.
18
+ - **For coding agents:** `CLAUDE.md` (also as `AGENTS.md`) and the `user-hub-auth` skill in `.claude/skills`.
19
+ - **`bun run setup`:** one command that creates your Convex project, registers the app with your hub and sets the values it needs.
20
+
21
+ ## Then
22
+
23
+ ```sh
24
+ cd my-app
25
+ bun run setup # connects Convex and the hub, once
26
+ bun run dev # http://localhost:3000
27
+ ```
package/index.js ADDED
@@ -0,0 +1,192 @@
1
+ #!/usr/bin/env bun
2
+ // bun create user-hub@latest [my-app] [--hub-url <url>]
3
+ // Copies the starter, names it, saves the hub's URL and admin password to
4
+ // .env.local, installs it and adds the agent skill.
5
+ //
6
+ // People are asked for anything missing (the password is typed as stars).
7
+ // Scripts and agents set HUB_URL and HUB_ADMIN_PASSWORD in the environment
8
+ // and are never asked. The password is never a command-line flag: that would
9
+ // leave it in shell history and process lists.
10
+ import { existsSync, readdirSync } from "node:fs";
11
+ import { cp, mkdir, readFile, rename, symlink, writeFile } from "node:fs/promises";
12
+ import { basename, join, resolve } from "node:path";
13
+ import { parseArgs } from "node:util";
14
+
15
+ const TEMPLATE = join(import.meta.dir, "template");
16
+ const SKILL = "node_modules/@user-hub/auth/skills/user-hub-auth";
17
+ const interactive = Boolean(process.stdin.isTTY);
18
+
19
+ function fail(message) {
20
+ console.error(`\n✗ ${message}`);
21
+ process.exit(1);
22
+ }
23
+
24
+ // "My App" -> "my-app"
25
+ function slug(text) {
26
+ return text
27
+ .toLowerCase()
28
+ .replace(/[^a-z0-9]+/g, "-")
29
+ .replace(/^-+|-+$/g, "");
30
+ }
31
+
32
+ // Reads a line without echoing it, printing a star per character.
33
+ function secret(question) {
34
+ process.stdout.write(question);
35
+ process.stdin.setRawMode(true);
36
+ process.stdin.resume();
37
+ process.stdin.setEncoding("utf8");
38
+ return new Promise((done) => {
39
+ let value = "";
40
+ const finish = () => {
41
+ process.stdin.off("data", onData);
42
+ process.stdin.setRawMode(false);
43
+ process.stdin.pause();
44
+ process.stdout.write("\n");
45
+ done(value);
46
+ };
47
+ const onData = (chunk) => {
48
+ for (const char of chunk) {
49
+ if (char === "\r" || char === "\n") return finish();
50
+ if (char === "\u0003") {
51
+ process.stdout.write("\n");
52
+ process.exit(130);
53
+ }
54
+ if (char === "\u007f" || char === "\b") {
55
+ if (value) {
56
+ value = value.slice(0, -1);
57
+ process.stdout.write("\b \b");
58
+ }
59
+ } else if (char >= " ") {
60
+ value += char;
61
+ process.stdout.write("*");
62
+ }
63
+ }
64
+ };
65
+ process.stdin.on("data", onData);
66
+ });
67
+ }
68
+
69
+ // The hub answers its public key at this path; anything else is a typo or a
70
+ // hub that is down.
71
+ async function hubAnswers(url) {
72
+ try {
73
+ const response = await fetch(`${url}/.well-known/jwks.json`, {
74
+ signal: AbortSignal.timeout(5000),
75
+ });
76
+ return response.ok;
77
+ } catch {
78
+ return false;
79
+ }
80
+ }
81
+
82
+ const { values: flags, positionals } = parseArgs({
83
+ args: process.argv.slice(2),
84
+ allowPositionals: true,
85
+ options: {
86
+ "hub-url": { type: "string" },
87
+ },
88
+ });
89
+
90
+ const target =
91
+ positionals[0] ??
92
+ (interactive ? prompt("App name:", "my-app") : null) ??
93
+ fail("Give the app a name: bun create user-hub@latest my-app");
94
+ const name = slug(basename(target));
95
+ if (!name) fail("Give the app a name: bun create user-hub@latest my-app");
96
+
97
+ const dest = resolve(target);
98
+ if (existsSync(dest) && readdirSync(dest).length > 0) {
99
+ fail(`${dest} already exists and is not empty.`);
100
+ }
101
+
102
+ let hubUrl = flags["hub-url"] ?? process.env.HUB_URL;
103
+ let adminPassword = process.env.HUB_ADMIN_PASSWORD;
104
+ if (interactive && (!hubUrl || !adminPassword)) {
105
+ console.log("\nYour hub's URL and admin password (from your hub's admin).");
106
+ console.log("Press Enter to skip and add them to .env.local later.\n");
107
+ hubUrl ||= prompt("Hub URL:") ?? "";
108
+ if (hubUrl) adminPassword ||= await secret("Admin password: ");
109
+ }
110
+ hubUrl = hubUrl?.trim().replace(/\/+$/, "");
111
+ if (hubUrl && !/^https?:\/\//.test(hubUrl)) {
112
+ fail(`The hub URL must start with https:// (got "${hubUrl}").`);
113
+ }
114
+ if (hubUrl && !(await hubAnswers(hubUrl))) {
115
+ fail(`No User Hub answers at ${hubUrl}. Check the URL with your hub's admin.`);
116
+ }
117
+
118
+ console.log(`\nCreating ${name} in ${dest}`);
119
+ await cp(TEMPLATE, dest, { recursive: true });
120
+ // npm drops .gitignore from packages, so the template ships it as gitignore.
121
+ await rename(join(dest, "gitignore"), join(dest, ".gitignore"));
122
+
123
+ for (const file of [
124
+ "package.json",
125
+ "README.md",
126
+ "CLAUDE.md",
127
+ "src/routes/__root.tsx",
128
+ "convex/hub.ts",
129
+ ]) {
130
+ const path = join(dest, file);
131
+ const text = await readFile(path, "utf8");
132
+ await writeFile(
133
+ path,
134
+ text.replaceAll("__APP_NAME__", name).replaceAll("__APP_KEY__", name),
135
+ );
136
+ }
137
+ await symlink("CLAUDE.md", join(dest, "AGENTS.md"));
138
+
139
+ // .env.local is gitignored; the password never goes anywhere else.
140
+ const env = [
141
+ hubUrl && `HUB_URL=${hubUrl}`,
142
+ adminPassword && `HUB_ADMIN_PASSWORD=${adminPassword}`,
143
+ ].filter(Boolean);
144
+ if (env.length > 0) {
145
+ await writeFile(join(dest, ".env.local"), `${env.join("\n")}\n`, {
146
+ mode: 0o600,
147
+ });
148
+ }
149
+
150
+ const run = (command) =>
151
+ Bun.spawn(command, { cwd: dest, stdio: ["inherit", "inherit", "inherit"] })
152
+ .exited;
153
+
154
+ console.log("\nInstalling dependencies");
155
+ if ((await run(["bun", "install"])) !== 0) fail("bun install failed.");
156
+
157
+ // The skill ships inside @user-hub/auth: one copy for every agent, linked
158
+ // for Claude Code.
159
+ await mkdir(join(dest, ".agents/skills"), { recursive: true });
160
+ await cp(join(dest, SKILL), join(dest, ".agents/skills/user-hub-auth"), {
161
+ recursive: true,
162
+ dereference: true,
163
+ });
164
+ await mkdir(join(dest, ".claude"), { recursive: true });
165
+ await symlink("../.agents/skills", join(dest, ".claude/skills"));
166
+
167
+ await run(["git", "init", "-q"]);
168
+
169
+ const ready = Boolean(hubUrl && adminPassword);
170
+ console.log(`
171
+ ✓ Created ${name}
172
+
173
+ Next:
174
+
175
+ cd ${target}
176
+ ${
177
+ ready
178
+ ? ""
179
+ : `
180
+ 0. Put your hub's URL and admin password in .env.local
181
+ (from your hub's admin):
182
+
183
+ HUB_URL=https://hub.example.com
184
+ HUB_ADMIN_PASSWORD=…
185
+ `
186
+ }
187
+ 1. bun run setup connects Convex and the hub, once
188
+ 2. bun run dev http://localhost:3000
189
+
190
+ Using a coding agent? It reads CLAUDE.md (AGENTS.md) and the
191
+ user-hub-auth skill in .claude/skills.
192
+ `);
package/package.json CHANGED
@@ -1,6 +1,14 @@
1
1
  {
2
2
  "name": "create-user-hub",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.3",
4
+ "description": "Start a TanStack Start + Convex app with User Hub sign-in: bun create user-hub@latest my-app",
5
+ "type": "module",
6
+ "bin": {
7
+ "create-user-hub": "./index.js"
8
+ },
9
+ "files": ["index.js", "template"],
10
+ "publishConfig": {
11
+ "access": "public"
12
+ },
13
+ "keywords": ["user-hub", "create", "template", "tanstack-start", "convex"]
14
+ }
@@ -0,0 +1,7 @@
1
+ # From your hub's admin. bun run setup reads them; never commit them.
2
+ HUB_URL=https://hub.example.com
3
+ HUB_ADMIN_PASSWORD=
4
+
5
+ # Written by bun run setup and the Convex CLI:
6
+ # CONVEX_DEPLOYMENT, VITE_CONVEX_URL, VITE_HUB_URL, HUB_APP_NAME (this app's
7
+ # name in the hub, once registered), HUB_APP_PROD_URL (once given)
@@ -0,0 +1,24 @@
1
+ # __APP_NAME__
2
+
3
+ A TanStack Start + Convex app whose sign-in comes from User Hub: people scan their badge and land here signed in. All auth comes from `@user-hub/auth`; follow the `user-hub-auth` skill in `.claude/skills` for anything about sign-in, roles or the hub.
4
+
5
+ ## How it is wired
6
+
7
+ - `convex/hub.ts`: this app's key in the hub (`APP_KEY`), written by `bun run setup`.
8
+ - `convex/auth.config.ts`: `hubAuth({ app: APP_KEY })`; Convex trusts hub tokens through `HUB_ISSUER` and `HUB_JWKS` on the deployment.
9
+ - `src/routes/__root.tsx`: `ConvexHubAuthProvider` and `HubSignedIn` inside `<body>`. Never move them outside `<html>` or into the router's `Wrap`.
10
+ - People: `useHubUser()` in components; `requireHubUser(ctx)` / `requireFacilitator(ctx)` in Convex functions. Key data on the person's hub id; check roles on the server.
11
+ - Sign out: `useHubSignOut()`.
12
+
13
+ ## Rules
14
+
15
+ - **Bun only:** `bun` and `bunx`; never `npm`, `npx`, `pnpm` or `yarn`.
16
+ - **Never hand-roll auth:** no login screens, passwords, sessions or token handling. If something is missing, it belongs in `@user-hub/auth`.
17
+ - **Secrets:** `HUB_ADMIN_PASSWORD` lives only in `.env.local`, set by the human. Never print, copy or commit it.
18
+ - **Convex:** public functions are thin wrappers (validators, an auth check, one call into `convex/model/`); every function has `args` and `returns` validators; reads use indexes and are bounded.
19
+ - **UI:** shadcn components only (`bunx --bun shadcn@latest add …`), dark theme, works on mobile. Lists are `Item`s in an `ItemGroup` with actions in a `ButtonGroup`, never tables; forms use `Field`.
20
+ - **Imports:** the `@/` alias for `src/`.
21
+
22
+ ## Commands
23
+
24
+ `bun run setup` (once), `bun run setup --prod <url>` (once deployed: registers the production URL so badge scans can reach the app; see the skill's "Production URL"), `bun run dev`, `bun run check`, `bun run typecheck`, `bun run build`.
@@ -0,0 +1,29 @@
1
+ # __APP_NAME__
2
+
3
+ A TanStack Start + Convex app with User Hub sign-in: people scan their badge and arrive signed in.
4
+
5
+ ## Get started
6
+
7
+ 1. Ask your hub's admin for the hub URL and admin password, and put them in `.env.local`:
8
+
9
+ ```sh
10
+ HUB_URL=https://hub.example.com
11
+ HUB_ADMIN_PASSWORD=…
12
+ ```
13
+
14
+ 2. `bun run setup`: creates your Convex project, registers the app with the hub and sets everything up. If another app already has this name in the hub, it asks you for a new one (or run `bun run setup --name <name>`). Safe to run again.
15
+ 3. `bun run dev`, then open http://localhost:3000. You are sent to the hub to pick who to be, then back signed in.
16
+ 4. Once the app is deployed: `bun run setup --prod https://your-app.example.com`, so badge scans can reach it. Setup asks for this the first time; press Enter to skip until you deploy.
17
+
18
+ ## What's inside
19
+
20
+ - `src/routes/__root.tsx`: the hub providers inside `<body>`; `HubSignedIn` shows pages only to signed-in people.
21
+ - `src/routes/index.tsx`: your name, team and role, what the server sees, sign-out, and notes saved per person.
22
+ - `src/routes/facilitator.tsx`: a facilitator-only page.
23
+ - `convex/`: notes keyed on the person's hub id. Public functions check who is asking (`requireHubUser`, `requireFacilitator`) and call `convex/model/`.
24
+
25
+ ## Commands
26
+
27
+ `bun run dev`, `bun run check` (Biome), `bun run typecheck`, `bun run build`, `bun run start` (production server).
28
+
29
+ Coding agents: see `CLAUDE.md` and the `user-hub-auth` skill in `.claude/skills`.
@@ -0,0 +1,46 @@
1
+ {
2
+ "$schema": "https://biomejs.dev/schemas/2.5.15/schema.json",
3
+ "vcs": {
4
+ "enabled": true,
5
+ "clientKind": "git",
6
+ "useIgnoreFile": true
7
+ },
8
+ "files": {
9
+ "ignoreUnknown": false,
10
+ "includes": [
11
+ "**",
12
+ "!**/src/routeTree.gen.ts",
13
+ "!**/convex/_generated",
14
+ "!**/.claude",
15
+ "!**/.agents"
16
+ ]
17
+ },
18
+ "formatter": {
19
+ "enabled": true,
20
+ "indentStyle": "space",
21
+ "indentWidth": 2
22
+ },
23
+ "assist": { "actions": { "source": { "organizeImports": "on" } } },
24
+ "linter": {
25
+ "enabled": true,
26
+ "rules": {
27
+ "preset": "recommended"
28
+ }
29
+ },
30
+ "javascript": {
31
+ "formatter": {
32
+ "quoteStyle": "double"
33
+ }
34
+ },
35
+ "css": {
36
+ "parser": {
37
+ "tailwindDirectives": true
38
+ }
39
+ },
40
+ "overrides": [
41
+ {
42
+ "includes": ["src/components/ui/**"],
43
+ "linter": { "enabled": false }
44
+ }
45
+ ]
46
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema.json",
3
+ "style": "base-luma",
4
+ "rsc": false,
5
+ "tsx": true,
6
+ "tailwind": {
7
+ "config": "",
8
+ "css": "src/styles.css",
9
+ "baseColor": "neutral",
10
+ "cssVariables": true,
11
+ "prefix": ""
12
+ },
13
+ "iconLibrary": "lucide",
14
+ "rtl": false,
15
+ "aliases": {
16
+ "components": "@/components",
17
+ "utils": "@/lib/utils",
18
+ "ui": "@/components/ui",
19
+ "lib": "@/lib",
20
+ "hooks": "@/hooks"
21
+ },
22
+ "menuColor": "default",
23
+ "menuAccent": "subtle",
24
+ "registries": {}
25
+ }
@@ -0,0 +1,56 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated `api` utility.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type * as hub from "../hub.js";
12
+ import type * as me from "../me.js";
13
+ import type * as model_notes from "../model/notes.js";
14
+ import type * as notes from "../notes.js";
15
+
16
+ import type {
17
+ ApiFromModules,
18
+ FilterApi,
19
+ FunctionReference,
20
+ } from "convex/server";
21
+ import { anyApi, componentsGeneric } from "convex/server";
22
+
23
+ const fullApi: ApiFromModules<{
24
+ hub: typeof hub;
25
+ me: typeof me;
26
+ "model/notes": typeof model_notes;
27
+ notes: typeof notes;
28
+ }> = anyApi as any;
29
+
30
+ /**
31
+ * A utility for referencing Convex functions in your app's public API.
32
+ *
33
+ * Usage:
34
+ * ```js
35
+ * const myFunctionReference = api.myModule.myFunction;
36
+ * ```
37
+ */
38
+ export const api: FilterApi<
39
+ typeof fullApi,
40
+ FunctionReference<any, "public">
41
+ > = anyApi as any;
42
+
43
+ /**
44
+ * A utility for referencing Convex functions in your app's internal API.
45
+ *
46
+ * Usage:
47
+ * ```js
48
+ * const myFunctionReference = internal.myModule.myFunction;
49
+ * ```
50
+ */
51
+ export const internal: FilterApi<
52
+ typeof fullApi,
53
+ FunctionReference<any, "internal">
54
+ > = anyApi as any;
55
+
56
+ export const components = componentsGeneric() as unknown as {};
@@ -0,0 +1,60 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated data model types.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import type {
12
+ DataModelFromSchemaDefinition,
13
+ DocumentByName,
14
+ TableNamesInDataModel,
15
+ SystemTableNames,
16
+ } from "convex/server";
17
+ import type { GenericId } from "convex/values";
18
+ import schema from "../schema.js";
19
+
20
+ /**
21
+ * The names of all of your Convex tables.
22
+ */
23
+ export type TableNames = TableNamesInDataModel<DataModel>;
24
+
25
+ /**
26
+ * The type of a document stored in Convex.
27
+ *
28
+ * @typeParam TableName - A string literal type of the table name (like "users").
29
+ */
30
+ export type Doc<TableName extends TableNames> = DocumentByName<
31
+ DataModel,
32
+ TableName
33
+ >;
34
+
35
+ /**
36
+ * An identifier for a document in Convex.
37
+ *
38
+ * Convex documents are uniquely identified by their `Id`, which is accessible
39
+ * on the `_id` field. To learn more, see [Document IDs](https://docs.convex.dev/using/document-ids).
40
+ *
41
+ * Documents can be loaded using `db.get(tableName, id)` in query and mutation functions.
42
+ *
43
+ * IDs are just strings at runtime, but this type can be used to distinguish them from other
44
+ * strings when type checking.
45
+ *
46
+ * @typeParam TableName - A string literal type of the table name (like "users").
47
+ */
48
+ export type Id<TableName extends TableNames | SystemTableNames> =
49
+ GenericId<TableName>;
50
+
51
+ /**
52
+ * A type describing your Convex data model.
53
+ *
54
+ * This type includes information about what tables you have, the type of
55
+ * documents stored in those tables, and the indexes defined on them.
56
+ *
57
+ * This type is used to parameterize methods like `queryGeneric` and
58
+ * `mutationGeneric` to make them type-safe.
59
+ */
60
+ export type DataModel = DataModelFromSchemaDefinition<typeof schema>;
@@ -0,0 +1,175 @@
1
+ /* eslint-disable */
2
+ /**
3
+ * Generated utilities for implementing server-side Convex query and mutation functions.
4
+ *
5
+ * THIS CODE IS AUTOMATICALLY GENERATED.
6
+ *
7
+ * To regenerate, run `npx convex dev`.
8
+ * @module
9
+ */
10
+
11
+ import {
12
+ actionGeneric,
13
+ httpActionGeneric,
14
+ queryGeneric,
15
+ mutationGeneric,
16
+ internalActionGeneric,
17
+ internalMutationGeneric,
18
+ internalQueryGeneric,
19
+ } from "convex/server";
20
+ import type {
21
+ ActionBuilder,
22
+ HttpActionBuilder,
23
+ MutationBuilder,
24
+ QueryBuilder,
25
+ GenericActionCtx,
26
+ GenericMutationCtx,
27
+ GenericQueryCtx,
28
+ GenericDatabaseReader,
29
+ GenericDatabaseWriter,
30
+ } from "convex/server";
31
+ import type { DataModel } from "./dataModel.js";
32
+
33
+ /**
34
+ * Typesafe environment variables.
35
+ *
36
+ * This includes platform-provided env vars and any variables declared in
37
+ * `convex.config.ts`.
38
+ */
39
+ type Env = {
40
+ readonly CONVEX_CLOUD_URL: string;
41
+ readonly CONVEX_SITE_URL: string;
42
+ };
43
+
44
+ /**
45
+ * Define a query in this Convex app's public API.
46
+ *
47
+ * This function will be allowed to read your Convex database and will be accessible from the client.
48
+ *
49
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
50
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
51
+ */
52
+ export const query: QueryBuilder<DataModel, "public"> = queryGeneric;
53
+
54
+ /**
55
+ * Define a query that is only accessible from other Convex functions (but not from the client).
56
+ *
57
+ * This function will be allowed to read from your Convex database. It will not be accessible from the client.
58
+ *
59
+ * @param func - The query function. It receives a {@link QueryCtx} as its first argument.
60
+ * @returns The wrapped query. Include this as an `export` to name it and make it accessible.
61
+ */
62
+ export const internalQuery: QueryBuilder<DataModel, "internal"> =
63
+ internalQueryGeneric;
64
+
65
+ /**
66
+ * Define a mutation in this Convex app's public API.
67
+ *
68
+ * This function will be allowed to modify your Convex database and will be accessible from the client.
69
+ *
70
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
71
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
72
+ */
73
+ export const mutation: MutationBuilder<DataModel, "public"> = mutationGeneric;
74
+
75
+ /**
76
+ * Define a mutation that is only accessible from other Convex functions (but not from the client).
77
+ *
78
+ * This function will be allowed to modify your Convex database. It will not be accessible from the client.
79
+ *
80
+ * @param func - The mutation function. It receives a {@link MutationCtx} as its first argument.
81
+ * @returns The wrapped mutation. Include this as an `export` to name it and make it accessible.
82
+ */
83
+ export const internalMutation: MutationBuilder<DataModel, "internal"> =
84
+ internalMutationGeneric;
85
+
86
+ /**
87
+ * Define an action in this Convex app's public API.
88
+ *
89
+ * An action is a function which can execute any JavaScript code, including non-deterministic
90
+ * code and code with side-effects, like calling third-party services.
91
+ * They can be run in Convex's JavaScript environment or in Node.js using the "use node" directive.
92
+ * They can interact with the database indirectly by calling queries and mutations using the {@link ActionCtx}.
93
+ *
94
+ * @param func - The action. It receives an {@link ActionCtx} as its first argument.
95
+ * @returns The wrapped action. Include this as an `export` to name it and make it accessible.
96
+ */
97
+ export const action: ActionBuilder<DataModel, "public"> = actionGeneric;
98
+
99
+ /**
100
+ * Define an action that is only accessible from other Convex functions (but not from the client).
101
+ *
102
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument.
103
+ * @returns The wrapped function. Include this as an `export` to name it and make it accessible.
104
+ */
105
+ export const internalAction: ActionBuilder<DataModel, "internal"> =
106
+ internalActionGeneric;
107
+
108
+ /**
109
+ * Define an HTTP action.
110
+ *
111
+ * The wrapped function will be used to respond to HTTP requests received
112
+ * by a Convex deployment if the requests matches the path and method where
113
+ * this action is routed. Be sure to route your httpAction in `convex/http.js`.
114
+ *
115
+ * @param func - The function. It receives an {@link ActionCtx} as its first argument
116
+ * and a Fetch API `Request` object as its second.
117
+ * @returns The wrapped function. Import this function from `convex/http.js` and route it to hook it up.
118
+ */
119
+ export const httpAction: HttpActionBuilder = httpActionGeneric;
120
+
121
+ /**
122
+ * Typesafe environment variables.
123
+ *
124
+ * This includes platform-provided env vars and any variables declared in
125
+ * `convex.config.ts`.
126
+ */
127
+ export const env: Env = (globalThis as unknown as { process: { env: Env } })
128
+ .process.env;
129
+
130
+ /**
131
+ * A set of services for use within Convex query functions.
132
+ *
133
+ * The query context is passed as the first argument to any Convex query
134
+ * function run on the server.
135
+ *
136
+ * This differs from the {@link MutationCtx} because all of the services are
137
+ * read-only.
138
+ */
139
+ export type QueryCtx = GenericQueryCtx<DataModel>;
140
+
141
+ /**
142
+ * A set of services for use within Convex mutation functions.
143
+ *
144
+ * The mutation context is passed as the first argument to any Convex mutation
145
+ * function run on the server.
146
+ */
147
+ export type MutationCtx = GenericMutationCtx<DataModel>;
148
+
149
+ /**
150
+ * A set of services for use within Convex action functions.
151
+ *
152
+ * The action context is passed as the first argument to any Convex action
153
+ * function run on the server.
154
+ */
155
+ export type ActionCtx = GenericActionCtx<DataModel>;
156
+
157
+ /**
158
+ * An interface to read from the database within Convex query functions.
159
+ *
160
+ * The two entry points are {@link DatabaseReader.get}, which fetches a single
161
+ * document by its {@link Id}, or {@link DatabaseReader.query}, which starts
162
+ * building a query.
163
+ */
164
+ export type DatabaseReader = GenericDatabaseReader<DataModel>;
165
+
166
+ /**
167
+ * An interface to read from and write to the database within Convex mutation
168
+ * functions.
169
+ *
170
+ * Convex guarantees that all writes within a single mutation are
171
+ * executed atomically, so you never have to worry about partial writes leaving
172
+ * your data in an inconsistent state. See [the Convex Guide](https://docs.convex.dev/understanding/convex-fundamentals/functions#atomicity-and-optimistic-concurrency-control)
173
+ * for the guarantees Convex provides your functions.
174
+ */
175
+ export type DatabaseWriter = GenericDatabaseWriter<DataModel>;
@@ -0,0 +1,7 @@
1
+ import { hubAuth } from "@user-hub/auth/convex";
2
+ import type { AuthConfig } from "convex/server";
3
+ import { APP_KEY } from "./hub";
4
+
5
+ // Trusts tokens from User Hub. HUB_ISSUER and HUB_JWKS are set on this Convex
6
+ // deployment by bun run setup.
7
+ export default { providers: [hubAuth({ app: APP_KEY })] } satisfies AuthConfig;
@@ -0,0 +1,2 @@
1
+ // This app's key in User Hub. bun run setup writes it from the hub's answer.
2
+ export const APP_KEY = "__APP_KEY__";