anhedral 0.15.0 → 0.16.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/README.md +29 -38
- package/assets/stack/ai-schema.ts.txt +5 -0
- package/assets/stack/ai.ts.txt +30 -0
- package/assets/stack/api-index.ts.txt +15 -0
- package/assets/stack/auth-features.ts.txt +4 -0
- package/assets/stack/auth-journal.json.txt +13 -0
- package/assets/stack/auth-migration.sql.txt +53 -0
- package/assets/stack/auth-routes.ts.txt +11 -0
- package/assets/stack/auth-schema.ts.txt +64 -0
- package/assets/stack/auth-snapshot.json.txt +346 -0
- package/assets/stack/auth.ts.txt +32 -0
- package/assets/stack/billing-mode.ts.txt +8 -0
- package/assets/stack/billing-schema.ts.txt +11 -0
- package/assets/stack/desktop.rs.txt +21 -0
- package/assets/stack/entitlement-guard.ts.txt +32 -0
- package/assets/stack/entitlements.ts.txt +8 -0
- package/assets/stack/events-schema.ts.txt +12 -0
- package/assets/stack/events.ts.txt +59 -0
- package/assets/stack/mobile-auth.ts.txt +25 -0
- package/assets/stack/mobile-billing.tsx.txt +63 -0
- package/assets/stack/mobile-session.tsx.txt +83 -0
- package/assets/stack/native-button.tsx.txt +108 -0
- package/assets/stack/native-global.css.txt +4 -0
- package/assets/stack/native-lib-utils.ts.txt +5 -0
- package/assets/stack/native-metro.config.js.txt +6 -0
- package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
- package/assets/stack/native-tailwind.config.js.txt +73 -0
- package/assets/stack/native-text.tsx.txt +89 -0
- package/assets/stack/purchases.ts.txt +65 -0
- package/assets/stack/revenuecat.ts.txt +88 -0
- package/assets/stack/rtc-schema.ts.txt +10 -0
- package/assets/stack/rtc.ts.txt +122 -0
- package/assets/stack/security.ts.txt +31 -0
- package/assets/stack/storage.ts.txt +36 -0
- package/assets/stack/stripe.ts.txt +126 -0
- package/assets/stack/web-sign-in.tsx.txt +51 -0
- package/assets/ui/LICENSE.react-native-reusables +21 -0
- package/assets/ui/UPSTREAM.json +7 -1
- package/assets/ui/catalog.json +891 -0
- package/assets/ui/extensions/registry.json +6 -0
- package/assets/ui/native/_controls.tsx +521 -0
- package/assets/ui/native/_core.tsx +118 -0
- package/assets/ui/native/_data.tsx +200 -0
- package/assets/ui/native/_display.tsx +453 -0
- package/assets/ui/native/_feedback.tsx +242 -0
- package/assets/ui/native/_legacy-dialog.tsx +38 -0
- package/assets/ui/native/_motion.tsx +520 -0
- package/assets/ui/native/_overlay.tsx +402 -0
- package/assets/ui/native/_selection.tsx +366 -0
- package/assets/ui/native/accordion.tsx +1 -0
- package/assets/ui/native/alert-dialog.tsx +11 -0
- package/assets/ui/native/alert.tsx +1 -0
- package/assets/ui/native/aspect-ratio.tsx +1 -0
- package/assets/ui/native/attachment.tsx +8 -0
- package/assets/ui/native/avatar.tsx +8 -0
- package/assets/ui/native/badge.tsx +1 -0
- package/assets/ui/native/breadcrumb.tsx +9 -0
- package/assets/ui/native/bubble.tsx +1 -0
- package/assets/ui/native/button-group.tsx +1 -0
- package/assets/ui/native/button.tsx +2 -1
- package/assets/ui/native/calendar.tsx +170 -0
- package/assets/ui/native/card.tsx +16 -5
- package/assets/ui/native/carousel.tsx +1 -0
- package/assets/ui/native/chart.tsx +193 -0
- package/assets/ui/native/checkbox.tsx +1 -0
- package/assets/ui/native/code-block.tsx +137 -0
- package/assets/ui/native/collapsible.tsx +1 -0
- package/assets/ui/native/combobox.tsx +1 -0
- package/assets/ui/native/command.tsx +11 -0
- package/assets/ui/native/context-menu.tsx +16 -0
- package/assets/ui/native/data-table.tsx +1 -0
- package/assets/ui/native/date-picker.tsx +43 -0
- package/assets/ui/native/dialog.tsx +14 -74
- package/assets/ui/native/direction.tsx +1 -0
- package/assets/ui/native/drawer.tsx +10 -0
- package/assets/ui/native/dropdown-menu.tsx +16 -0
- package/assets/ui/native/empty.tsx +8 -0
- package/assets/ui/native/field.tsx +13 -0
- package/assets/ui/native/hover-card.tsx +1 -0
- package/assets/ui/native/input-group.tsx +8 -0
- package/assets/ui/native/input-otp.tsx +1 -0
- package/assets/ui/native/input.tsx +2 -1
- package/assets/ui/native/item.tsx +12 -0
- package/assets/ui/native/kbd.tsx +1 -0
- package/assets/ui/native/marker.tsx +1 -0
- package/assets/ui/native/menubar.tsx +17 -0
- package/assets/ui/native/message-scroller.tsx +6 -0
- package/assets/ui/native/message.tsx +10 -0
- package/assets/ui/native/native-select.tsx +1 -0
- package/assets/ui/native/navigation-menu.tsx +10 -0
- package/assets/ui/native/pagination.tsx +9 -0
- package/assets/ui/native/popover.tsx +1 -0
- package/assets/ui/native/progress.tsx +1 -0
- package/assets/ui/native/questionnaire.tsx +130 -0
- package/assets/ui/native/radio-group.tsx +1 -0
- package/assets/ui/native/registry.json +1103 -0
- package/assets/ui/native/resizable.tsx +1 -0
- package/assets/ui/native/scroll-area.tsx +1 -0
- package/assets/ui/native/select.tsx +11 -0
- package/assets/ui/native/separator.tsx +1 -0
- package/assets/ui/native/sheet.tsx +10 -0
- package/assets/ui/native/sidebar.tsx +22 -0
- package/assets/ui/native/skeleton.tsx +1 -0
- package/assets/ui/native/slider.tsx +1 -0
- package/assets/ui/native/spinner.tsx +1 -0
- package/assets/ui/native/switch.tsx +1 -0
- package/assets/ui/native/table.tsx +10 -0
- package/assets/ui/native/tabs.tsx +1 -0
- package/assets/ui/native/textarea.tsx +1 -0
- package/assets/ui/native/toast.tsx +11 -0
- package/assets/ui/native/toggle-group.tsx +1 -0
- package/assets/ui/native/toggle.tsx +1 -0
- package/assets/ui/native/tooltip.tsx +1 -0
- package/assets/ui/native/trace.tsx +20 -0
- package/assets/ui/native/typography.tsx +15 -0
- package/dist/bin.js +7 -12
- package/dist/capabilities.d.ts +4 -33
- package/dist/capabilities.js +2 -66
- package/dist/capability-catalog.d.ts +83 -0
- package/dist/capability-catalog.js +121 -0
- package/dist/capability-command.d.ts +3 -0
- package/dist/capability-command.js +188 -0
- package/dist/capability-editor.d.ts +17 -0
- package/dist/capability-editor.js +97 -0
- package/dist/capability-recipes.d.ts +4 -0
- package/dist/capability-recipes.js +520 -0
- package/dist/capability-references.d.ts +4 -0
- package/dist/capability-references.js +7 -0
- package/dist/cli-commands.d.ts +1 -2
- package/dist/cli-commands.js +10 -104
- package/dist/cli-output.d.ts +1 -2
- package/dist/cli-output.js +6 -251
- package/dist/command-schema.js +39 -322
- package/dist/dependencies.d.ts +29 -6
- package/dist/dependencies.js +61 -14
- package/dist/index.d.ts +1 -42
- package/dist/index.js +1 -27
- package/dist/platforms/mobile.js +1 -20
- package/dist/platforms/web.d.ts +1 -1
- package/dist/platforms/web.js +27 -75
- package/dist/project-config.d.ts +2 -13
- package/dist/project-config.js +10 -82
- package/dist/registry/options.js +1 -5
- package/dist/registry/resolve.d.ts +1 -1
- package/dist/registry/resolve.js +2 -10
- package/dist/registry/usage.js +3 -9
- package/dist/scaffold/backend.js +0 -3
- package/dist/scaffold/database.js +2 -1
- package/dist/scaffold/documentation.js +82 -20
- package/dist/scaffold/expo-runtime.js +3 -4
- package/dist/scaffold/native-ui.js +12 -7
- package/dist/scaffold/stack-documentation.js +1 -1
- package/dist/scaffold/storage.d.ts +2 -0
- package/dist/scaffold/storage.js +21 -0
- package/dist/scaffold/workspace.js +26 -21
- package/dist/stack-registry.d.ts +2 -8
- package/dist/stack-registry.js +11 -87
- package/dist/standard.js +1 -11
- package/dist/ui-catalog.d.ts +26 -0
- package/dist/ui-catalog.js +31 -0
- package/dist/ui-command.d.ts +3 -0
- package/dist/ui-command.js +219 -0
- package/dist/ui-project.d.ts +22 -0
- package/dist/ui-project.js +110 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/anhedral-stack.md +4 -20
- package/docs/capabilities.md +110 -0
- package/docs/native-ui.md +102 -0
- package/docs/software-factory.md +16 -44
- package/docs/stack-standard.md +11 -60
- package/docs/ui.md +33 -0
- package/docs/verification.md +191 -0
- package/package.json +19 -18
- package/dist/access.d.ts +0 -10
- package/dist/access.js +0 -93
- package/dist/auth-schema-snapshot.d.ts +0 -346
- package/dist/auth-schema-snapshot.js +0 -347
- package/dist/auth-schema.d.ts +0 -1
- package/dist/auth-schema.js +0 -57
- package/dist/capability-contract.d.ts +0 -47
- package/dist/capability-contract.js +0 -129
- package/dist/catalog-model.d.ts +0 -24
- package/dist/catalog-model.js +0 -1
- package/dist/catalog-registration.d.ts +0 -16
- package/dist/catalog-registration.js +0 -22
- package/dist/catalog-snapshot.d.ts +0 -5
- package/dist/catalog-snapshot.js +0 -97
- package/dist/cli-delivery.d.ts +0 -3
- package/dist/cli-delivery.js +0 -112
- package/dist/cloudflare.d.ts +0 -25
- package/dist/cloudflare.js +0 -226
- package/dist/delivery-evidence.d.ts +0 -62
- package/dist/delivery-evidence.js +0 -157
- package/dist/delivery.d.ts +0 -82
- package/dist/delivery.js +0 -489
- package/dist/inspector-model.d.ts +0 -123
- package/dist/inspector-model.js +0 -1
- package/dist/integration-service-readers.d.ts +0 -12
- package/dist/integration-service-readers.js +0 -92
- package/dist/lifecycle-model.d.ts +0 -15
- package/dist/lifecycle-model.js +0 -20
- package/dist/lifecycle.d.ts +0 -11
- package/dist/lifecycle.js +0 -91
- package/dist/management.d.ts +0 -3
- package/dist/management.js +0 -47
- package/dist/mobile-delivery.d.ts +0 -77
- package/dist/mobile-delivery.js +0 -370
- package/dist/project-catalog.d.ts +0 -41
- package/dist/project-catalog.js +0 -288
- package/dist/project-inspector.d.ts +0 -4
- package/dist/project-inspector.js +0 -671
- package/dist/project-lifecycle.d.ts +0 -25
- package/dist/project-lifecycle.js +0 -57
- package/dist/project-state.d.ts +0 -47
- package/dist/project-state.js +0 -480
- package/dist/provider-auth.d.ts +0 -41
- package/dist/provider-auth.js +0 -180
- package/dist/provider-readiness.d.ts +0 -30
- package/dist/provider-readiness.js +0 -85
- package/dist/providers/adapters.d.ts +0 -17
- package/dist/providers/adapters.js +0 -103
- package/dist/providers/api.d.ts +0 -29
- package/dist/providers/api.js +0 -253
- package/dist/providers/config.d.ts +0 -15
- package/dist/providers/config.js +0 -136
- package/dist/providers/definitions.d.ts +0 -115
- package/dist/providers/definitions.js +0 -42
- package/dist/providers/provision.d.ts +0 -24
- package/dist/providers/provision.js +0 -76
- package/dist/providers/receipts.d.ts +0 -20
- package/dist/providers/receipts.js +0 -56
- package/dist/providers/recovery-verification.d.ts +0 -7
- package/dist/providers/recovery-verification.js +0 -52
- package/dist/providers/recovery.d.ts +0 -30
- package/dist/providers/recovery.js +0 -34
- package/dist/providers/runtime.d.ts +0 -10
- package/dist/providers/runtime.js +0 -234
- package/dist/providers/schema.d.ts +0 -28
- package/dist/providers/schema.js +0 -49
- package/dist/providers/state.d.ts +0 -55
- package/dist/providers/state.js +0 -283
- package/dist/provision.d.ts +0 -47
- package/dist/provision.js +0 -208
- package/dist/r2-service-data.d.ts +0 -2
- package/dist/r2-service-data.js +0 -136
- package/dist/readiness.d.ts +0 -23
- package/dist/readiness.js +0 -117
- package/dist/registry/add.d.ts +0 -24
- package/dist/registry/add.js +0 -210
- package/dist/registry/bootstrap.d.ts +0 -3
- package/dist/registry/bootstrap.js +0 -5
- package/dist/registry/commands.d.ts +0 -3
- package/dist/registry/commands.js +0 -83
- package/dist/registry/preview.d.ts +0 -11
- package/dist/registry/preview.js +0 -91
- package/dist/registry/receipt.d.ts +0 -3
- package/dist/registry/receipt.js +0 -68
- package/dist/repository.d.ts +0 -24
- package/dist/repository.js +0 -96
- package/dist/scaffold/auth.d.ts +0 -2
- package/dist/scaffold/auth.js +0 -76
- package/dist/scaffold/billing-config.d.ts +0 -1
- package/dist/scaffold/billing-config.js +0 -73
- package/dist/scaffold/billing-contracts.d.ts +0 -2
- package/dist/scaffold/billing-contracts.js +0 -48
- package/dist/scaffold/billing-providers.d.ts +0 -1
- package/dist/scaffold/billing-providers.js +0 -249
- package/dist/scaffold/billing-schema.d.ts +0 -1
- package/dist/scaffold/billing-schema.js +0 -34
- package/dist/scaffold/billing-security.d.ts +0 -1
- package/dist/scaffold/billing-security.js +0 -46
- package/dist/scaffold/billing-server.d.ts +0 -1
- package/dist/scaffold/billing-server.js +0 -139
- package/dist/scaffold/billing-store.d.ts +0 -1
- package/dist/scaffold/billing-store.js +0 -72
- package/dist/scaffold/billing.d.ts +0 -2
- package/dist/scaffold/billing.js +0 -208
- package/dist/scaffold/expo-auth.d.ts +0 -3
- package/dist/scaffold/expo-auth.js +0 -203
- package/dist/scaffold/expo-billing.d.ts +0 -3
- package/dist/scaffold/expo-billing.js +0 -257
- package/dist/scaffold/integrations.d.ts +0 -2
- package/dist/scaffold/integrations.js +0 -11
- package/dist/scaffold/managed-email.d.ts +0 -3
- package/dist/scaffold/managed-email.js +0 -47
- package/dist/scaffold/password-reset.d.ts +0 -1
- package/dist/scaffold/password-reset.js +0 -99
- package/dist/scaffold/private-files.d.ts +0 -2
- package/dist/scaffold/private-files.js +0 -78
- package/dist/scaffold/web-billing.d.ts +0 -2
- package/dist/scaffold/web-billing.js +0 -48
- package/dist/service-deletion.d.ts +0 -29
- package/dist/service-deletion.js +0 -195
- package/dist/service-descriptor.d.ts +0 -10
- package/dist/service-descriptor.js +0 -71
- package/dist/service-model.d.ts +0 -49
- package/dist/service-model.js +0 -8
- package/dist/service-operations.d.ts +0 -29
- package/dist/service-operations.js +0 -48
- package/dist/service-readers.d.ts +0 -8
- package/dist/service-readers.js +0 -216
- package/dist/services-command.d.ts +0 -39
- package/dist/services-command.js +0 -96
- package/dist/ship.d.ts +0 -35
- package/dist/ship.js +0 -107
- package/docs/assets/anhedral-stack-light.png +0 -0
- package/docs/assets/anhedral-stack.png +0 -0
package/README.md
CHANGED
|
@@ -1,55 +1,46 @@
|
|
|
1
1
|
# Anhedral CLI
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Start with one Next.js application configured for OpenNext on Cloudflare Workers, with Anhedral UI included as editable source. Add architecture when a product needs it.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Generated applications are editable source that developers can customize and license for their products.
|
|
5
|
+
```sh
|
|
6
|
+
anhedral init my-app
|
|
7
|
+
cd my-app
|
|
8
|
+
pnpm dev
|
|
9
|
+
```
|
|
11
10
|
|
|
12
|
-
|
|
11
|
+
Init creates only `apps/web` plus shared tooling and tokens. It includes three reviewed web starter components (Button, Input and Label), official shadcn configuration and Anhedral UI metadata. It creates no Expo app, API, database, authentication or cloud resources.
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
```sh
|
|
14
|
+
anhedral init my-app --dry-run --json
|
|
15
|
+
anhedral init my-app --skip-install --no-git
|
|
16
|
+
anhedral ui list
|
|
17
|
+
anhedral ui add card --web
|
|
18
|
+
anhedral ui diff card --web
|
|
19
|
+
anhedral ui doctor --web
|
|
20
|
+
```
|
|
20
21
|
|
|
21
|
-
|
|
22
|
+
Anhedral UI is a small catalog and CLI over official shadcn on web and React Native Reusables on native. Components are copied into your application. Native resolution prefers a reviewed Anhedral extension when one exists, then RNR; unsupported components are reported. The extension registry starts empty. There is no Anhedral component runtime, whole-library fork or automatic source replacement.
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
<source media="(prefers-color-scheme: dark)" srcset="docs/assets/anhedral-stack.png">
|
|
25
|
-
<source media="(prefers-color-scheme: light)" srcset="docs/assets/anhedral-stack-light.png">
|
|
26
|
-
<img alt="Next.js web and Expo iOS/Android connect to Hono, Drizzle/D1 and private R2. Stripe and RevenueCat are optional payment additions." src="docs/assets/anhedral-stack-light.png" width="1200">
|
|
27
|
-
</picture>
|
|
24
|
+
For an existing Expo app, complete the upstream React Native Reusables NativeWind 4 setup first, then use `anhedral ui init --native`. Ambiguous workspaces require `--web`, `--native`, `--all` or an application-specific `--cwd`. UI installation does not require Hono, a database or authentication.
|
|
28
25
|
|
|
29
|
-
|
|
30
|
-
with `pnpm install --frozen-lockfile && pnpm build`, then use its local CLI.
|
|
31
|
-
For the examples below, replace `anhedral` with `node /path/to/anhedral-cli/dist/bin.js`
|
|
32
|
-
until the matching version is published.
|
|
26
|
+
Add the rest strategically through the CLI:
|
|
33
27
|
|
|
34
28
|
```sh
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
anhedral stack list
|
|
30
|
+
anhedral add hono
|
|
31
|
+
anhedral add database-auth
|
|
32
|
+
anhedral add expo native-ui --dry-run --json
|
|
33
|
+
anhedral add side-panel --with-dependencies --dry-run --json
|
|
38
34
|
```
|
|
39
35
|
|
|
40
|
-
|
|
36
|
+
The catalog includes private R2, Stripe, events, RTC, AI, Expo, native UI, RevenueCat, WXT, Side Panel and GPUI. Missing prerequisites require an explicit selection or `--with-dependencies`. “If needed” decisions remain open. Additions preserve edited source and do not provision providers, install credentials, migrate databases or deploy. Anhedral Platform remains a separate managed product; no Platform account is required.
|
|
41
37
|
|
|
42
|
-
|
|
43
|
-
anhedral init my-app --dry-run --json
|
|
44
|
-
anhedral init my-app --stripe --revenuecat
|
|
45
|
-
anhedral add stripe --cwd my-app --dry-run --json
|
|
46
|
-
anhedral add stripe --cwd my-app
|
|
47
|
-
```
|
|
38
|
+
See [stack standard](docs/stack-standard.md), [workflow](docs/software-factory.md) and [UI commands](docs/ui.md) and [stack additions](docs/capabilities.md).
|
|
48
39
|
|
|
49
|
-
|
|
40
|
+
## Compatibility
|
|
50
41
|
|
|
51
|
-
|
|
42
|
+
This changes the default generated layout. Existing applications, Platform runtime images and installed plugins keep their reviewed pins until explicitly upgraded. The retained legacy native source and full-stack recipes are compatibility material; new init does not copy them. Publishing does not update an existing application or installed plugin.
|
|
52
43
|
|
|
53
|
-
|
|
44
|
+
For source development, run `pnpm install --frozen-lockfile && pnpm build`, then `node dist/bin.js init my-app`.
|
|
54
45
|
|
|
55
|
-
|
|
46
|
+
Apache-2.0. Generated applications are editable source that consumers may customize and license for their own products. Retain the applicable MIT notices for copied upstream UI source.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { requireSession } from '../security';
|
|
4
|
+
import type { AppEnv } from '../environment';
|
|
5
|
+
export const aiRoutes = new Hono<AppEnv>();
|
|
6
|
+
const configuration = z.object({
|
|
7
|
+
AI_MODEL: z.string().min(1),
|
|
8
|
+
AI_DAILY_LIMIT: z.coerce.number().int().min(1).max(1000),
|
|
9
|
+
});
|
|
10
|
+
const input = z.object({ prompt: z.string().trim().min(1).max(4000) });
|
|
11
|
+
aiRoutes.post('/ai/generate', requireSession, async (c) => {
|
|
12
|
+
const config = configuration.safeParse(c.env);
|
|
13
|
+
if (!config.success)
|
|
14
|
+
return c.json({ error: 'Choose a model and a daily limit from 1 to 1000' }, 503);
|
|
15
|
+
const body = input.safeParse(await c.req.json().catch(() => null));
|
|
16
|
+
if (!body.success) return c.json({ error: 'Prompt must contain 1–4000 characters' }, 400);
|
|
17
|
+
const key = c.get('userId') + ':' + new Date().toISOString().slice(0, 10);
|
|
18
|
+
const quota = await c.env.DB.prepare(
|
|
19
|
+
'INSERT INTO ai_usage(id,count) VALUES (?,1) ON CONFLICT(id) DO UPDATE SET count = count + 1 WHERE count < ? RETURNING count',
|
|
20
|
+
)
|
|
21
|
+
.bind(key, config.data.AI_DAILY_LIMIT)
|
|
22
|
+
.first();
|
|
23
|
+
if (!quota) return c.json({ error: 'Daily AI limit reached' }, 429);
|
|
24
|
+
// Failed provider calls consume quota as well; retrying cannot bypass the limit.
|
|
25
|
+
const result = await c.env.AI.run(config.data.AI_MODEL as Parameters<Ai['run']>[0], {
|
|
26
|
+
messages: [{ role: 'user', content: body.data.prompt }],
|
|
27
|
+
max_tokens: 512,
|
|
28
|
+
});
|
|
29
|
+
return c.json({ result });
|
|
30
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { bodyLimit } from 'hono/body-limit';
|
|
3
|
+
import { capabilities } from './capabilities';
|
|
4
|
+
import type { AppEnv } from './environment';
|
|
5
|
+
|
|
6
|
+
const app = new Hono<AppEnv>();
|
|
7
|
+
app.use('/api/*', bodyLimit({ maxSize: 1024 * 1024 }));
|
|
8
|
+
app.use('/api/*', async (c, next) => {
|
|
9
|
+
await next();
|
|
10
|
+
c.header('Cache-Control', 'private, no-store');
|
|
11
|
+
});
|
|
12
|
+
app.get('/api/health', (c) => c.json({ ok: true }));
|
|
13
|
+
app.route('/api', capabilities);
|
|
14
|
+
app.onError((_error, c) => c.json({ error: 'Application request failed' }, 500));
|
|
15
|
+
export default app;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// Enable methods deliberately after configuring credentials, email and policies.
|
|
2
|
+
// OAuth, passkeys, MFA and organizations each need their matching provider/plugin,
|
|
3
|
+
// schema generation, reviewed migrations and client configuration before use.
|
|
4
|
+
export const authFeatures = { emailPassword: false };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
CREATE TABLE `account` (
|
|
2
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
3
|
+
`account_id` text NOT NULL,
|
|
4
|
+
`provider_id` text NOT NULL,
|
|
5
|
+
`user_id` text NOT NULL,
|
|
6
|
+
`access_token` text,
|
|
7
|
+
`refresh_token` text,
|
|
8
|
+
`id_token` text,
|
|
9
|
+
`access_token_expires_at` integer,
|
|
10
|
+
`refresh_token_expires_at` integer,
|
|
11
|
+
`scope` text,
|
|
12
|
+
`password` text,
|
|
13
|
+
`created_at` integer NOT NULL,
|
|
14
|
+
`updated_at` integer NOT NULL,
|
|
15
|
+
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
|
16
|
+
);
|
|
17
|
+
--> statement-breakpoint
|
|
18
|
+
CREATE INDEX `account_user_id_idx` ON `account` (`user_id`);--> statement-breakpoint
|
|
19
|
+
CREATE TABLE `session` (
|
|
20
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
21
|
+
`expires_at` integer NOT NULL,
|
|
22
|
+
`token` text NOT NULL,
|
|
23
|
+
`created_at` integer NOT NULL,
|
|
24
|
+
`updated_at` integer NOT NULL,
|
|
25
|
+
`ip_address` text,
|
|
26
|
+
`user_agent` text,
|
|
27
|
+
`user_id` text NOT NULL,
|
|
28
|
+
FOREIGN KEY (`user_id`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade
|
|
29
|
+
);
|
|
30
|
+
--> statement-breakpoint
|
|
31
|
+
CREATE UNIQUE INDEX `session_token_unique` ON `session` (`token`);--> statement-breakpoint
|
|
32
|
+
CREATE INDEX `session_user_id_idx` ON `session` (`user_id`);--> statement-breakpoint
|
|
33
|
+
CREATE TABLE `user` (
|
|
34
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
35
|
+
`name` text NOT NULL,
|
|
36
|
+
`email` text NOT NULL,
|
|
37
|
+
`email_verified` integer DEFAULT false NOT NULL,
|
|
38
|
+
`image` text,
|
|
39
|
+
`created_at` integer NOT NULL,
|
|
40
|
+
`updated_at` integer NOT NULL
|
|
41
|
+
);
|
|
42
|
+
--> statement-breakpoint
|
|
43
|
+
CREATE UNIQUE INDEX `user_email_unique` ON `user` (`email`);--> statement-breakpoint
|
|
44
|
+
CREATE TABLE `verification` (
|
|
45
|
+
`id` text PRIMARY KEY NOT NULL,
|
|
46
|
+
`identifier` text NOT NULL,
|
|
47
|
+
`value` text NOT NULL,
|
|
48
|
+
`expires_at` integer NOT NULL,
|
|
49
|
+
`created_at` integer NOT NULL,
|
|
50
|
+
`updated_at` integer NOT NULL
|
|
51
|
+
);
|
|
52
|
+
--> statement-breakpoint
|
|
53
|
+
CREATE INDEX `verification_identifier_idx` ON `verification` (`identifier`);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Hono } from 'hono';
|
|
2
|
+
import { createAuth, authConfiguration } from '../auth';
|
|
3
|
+
import { requireSession } from '../security';
|
|
4
|
+
import type { AppEnv } from '../environment';
|
|
5
|
+
export const authRoutes = new Hono<AppEnv>();
|
|
6
|
+
authRoutes.on(['GET', 'POST'], '/auth/*', (c) => {
|
|
7
|
+
if (!authConfiguration.safeParse(c.env).success)
|
|
8
|
+
return c.json({ error: 'Authentication needs configuration' }, 503);
|
|
9
|
+
return createAuth(c.env).handler(c.req.raw);
|
|
10
|
+
});
|
|
11
|
+
authRoutes.get('/session', requireSession, (c) => c.json({ userId: c.get('userId') }));
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { index, integer, sqliteTable, text } from 'drizzle-orm/sqlite-core';
|
|
2
|
+
const timestamps = () => ({
|
|
3
|
+
createdAt: integer('created_at', { mode: 'timestamp_ms' })
|
|
4
|
+
.notNull()
|
|
5
|
+
.$defaultFn(() => new Date()),
|
|
6
|
+
updatedAt: integer('updated_at', { mode: 'timestamp_ms' })
|
|
7
|
+
.notNull()
|
|
8
|
+
.$defaultFn(() => new Date())
|
|
9
|
+
.$onUpdate(() => new Date()),
|
|
10
|
+
});
|
|
11
|
+
export const user = sqliteTable('user', {
|
|
12
|
+
id: text('id').primaryKey(),
|
|
13
|
+
name: text('name').notNull(),
|
|
14
|
+
email: text('email').notNull().unique(),
|
|
15
|
+
emailVerified: integer('email_verified', { mode: 'boolean' }).notNull().default(false),
|
|
16
|
+
image: text('image'),
|
|
17
|
+
...timestamps(),
|
|
18
|
+
});
|
|
19
|
+
export const session = sqliteTable(
|
|
20
|
+
'session',
|
|
21
|
+
{
|
|
22
|
+
id: text('id').primaryKey(),
|
|
23
|
+
expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
|
|
24
|
+
token: text('token').notNull().unique(),
|
|
25
|
+
...timestamps(),
|
|
26
|
+
ipAddress: text('ip_address'),
|
|
27
|
+
userAgent: text('user_agent'),
|
|
28
|
+
userId: text('user_id')
|
|
29
|
+
.notNull()
|
|
30
|
+
.references(() => user.id, { onDelete: 'cascade' }),
|
|
31
|
+
},
|
|
32
|
+
(t) => [index('session_user_id_idx').on(t.userId)],
|
|
33
|
+
);
|
|
34
|
+
export const account = sqliteTable(
|
|
35
|
+
'account',
|
|
36
|
+
{
|
|
37
|
+
id: text('id').primaryKey(),
|
|
38
|
+
accountId: text('account_id').notNull(),
|
|
39
|
+
providerId: text('provider_id').notNull(),
|
|
40
|
+
userId: text('user_id')
|
|
41
|
+
.notNull()
|
|
42
|
+
.references(() => user.id, { onDelete: 'cascade' }),
|
|
43
|
+
accessToken: text('access_token'),
|
|
44
|
+
refreshToken: text('refresh_token'),
|
|
45
|
+
idToken: text('id_token'),
|
|
46
|
+
accessTokenExpiresAt: integer('access_token_expires_at', { mode: 'timestamp_ms' }),
|
|
47
|
+
refreshTokenExpiresAt: integer('refresh_token_expires_at', { mode: 'timestamp_ms' }),
|
|
48
|
+
scope: text('scope'),
|
|
49
|
+
password: text('password'),
|
|
50
|
+
...timestamps(),
|
|
51
|
+
},
|
|
52
|
+
(t) => [index('account_user_id_idx').on(t.userId)],
|
|
53
|
+
);
|
|
54
|
+
export const verification = sqliteTable(
|
|
55
|
+
'verification',
|
|
56
|
+
{
|
|
57
|
+
id: text('id').primaryKey(),
|
|
58
|
+
identifier: text('identifier').notNull(),
|
|
59
|
+
value: text('value').notNull(),
|
|
60
|
+
expiresAt: integer('expires_at', { mode: 'timestamp_ms' }).notNull(),
|
|
61
|
+
...timestamps(),
|
|
62
|
+
},
|
|
63
|
+
(t) => [index('verification_identifier_idx').on(t.identifier)],
|
|
64
|
+
);
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "6",
|
|
3
|
+
"dialect": "sqlite",
|
|
4
|
+
"id": "b0e40d2d-45e2-4317-9f1b-ec413de82c9f",
|
|
5
|
+
"prevId": "00000000-0000-0000-0000-000000000000",
|
|
6
|
+
"tables": {
|
|
7
|
+
"account": {
|
|
8
|
+
"name": "account",
|
|
9
|
+
"columns": {
|
|
10
|
+
"id": {
|
|
11
|
+
"name": "id",
|
|
12
|
+
"type": "text",
|
|
13
|
+
"primaryKey": true,
|
|
14
|
+
"notNull": true,
|
|
15
|
+
"autoincrement": false
|
|
16
|
+
},
|
|
17
|
+
"account_id": {
|
|
18
|
+
"name": "account_id",
|
|
19
|
+
"type": "text",
|
|
20
|
+
"primaryKey": false,
|
|
21
|
+
"notNull": true,
|
|
22
|
+
"autoincrement": false
|
|
23
|
+
},
|
|
24
|
+
"provider_id": {
|
|
25
|
+
"name": "provider_id",
|
|
26
|
+
"type": "text",
|
|
27
|
+
"primaryKey": false,
|
|
28
|
+
"notNull": true,
|
|
29
|
+
"autoincrement": false
|
|
30
|
+
},
|
|
31
|
+
"user_id": {
|
|
32
|
+
"name": "user_id",
|
|
33
|
+
"type": "text",
|
|
34
|
+
"primaryKey": false,
|
|
35
|
+
"notNull": true,
|
|
36
|
+
"autoincrement": false
|
|
37
|
+
},
|
|
38
|
+
"access_token": {
|
|
39
|
+
"name": "access_token",
|
|
40
|
+
"type": "text",
|
|
41
|
+
"primaryKey": false,
|
|
42
|
+
"notNull": false,
|
|
43
|
+
"autoincrement": false
|
|
44
|
+
},
|
|
45
|
+
"refresh_token": {
|
|
46
|
+
"name": "refresh_token",
|
|
47
|
+
"type": "text",
|
|
48
|
+
"primaryKey": false,
|
|
49
|
+
"notNull": false,
|
|
50
|
+
"autoincrement": false
|
|
51
|
+
},
|
|
52
|
+
"id_token": {
|
|
53
|
+
"name": "id_token",
|
|
54
|
+
"type": "text",
|
|
55
|
+
"primaryKey": false,
|
|
56
|
+
"notNull": false,
|
|
57
|
+
"autoincrement": false
|
|
58
|
+
},
|
|
59
|
+
"access_token_expires_at": {
|
|
60
|
+
"name": "access_token_expires_at",
|
|
61
|
+
"type": "integer",
|
|
62
|
+
"primaryKey": false,
|
|
63
|
+
"notNull": false,
|
|
64
|
+
"autoincrement": false
|
|
65
|
+
},
|
|
66
|
+
"refresh_token_expires_at": {
|
|
67
|
+
"name": "refresh_token_expires_at",
|
|
68
|
+
"type": "integer",
|
|
69
|
+
"primaryKey": false,
|
|
70
|
+
"notNull": false,
|
|
71
|
+
"autoincrement": false
|
|
72
|
+
},
|
|
73
|
+
"scope": {
|
|
74
|
+
"name": "scope",
|
|
75
|
+
"type": "text",
|
|
76
|
+
"primaryKey": false,
|
|
77
|
+
"notNull": false,
|
|
78
|
+
"autoincrement": false
|
|
79
|
+
},
|
|
80
|
+
"password": {
|
|
81
|
+
"name": "password",
|
|
82
|
+
"type": "text",
|
|
83
|
+
"primaryKey": false,
|
|
84
|
+
"notNull": false,
|
|
85
|
+
"autoincrement": false
|
|
86
|
+
},
|
|
87
|
+
"created_at": {
|
|
88
|
+
"name": "created_at",
|
|
89
|
+
"type": "integer",
|
|
90
|
+
"primaryKey": false,
|
|
91
|
+
"notNull": true,
|
|
92
|
+
"autoincrement": false
|
|
93
|
+
},
|
|
94
|
+
"updated_at": {
|
|
95
|
+
"name": "updated_at",
|
|
96
|
+
"type": "integer",
|
|
97
|
+
"primaryKey": false,
|
|
98
|
+
"notNull": true,
|
|
99
|
+
"autoincrement": false
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"indexes": {
|
|
103
|
+
"account_user_id_idx": {
|
|
104
|
+
"name": "account_user_id_idx",
|
|
105
|
+
"columns": ["user_id"],
|
|
106
|
+
"isUnique": false
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"foreignKeys": {
|
|
110
|
+
"account_user_id_user_id_fk": {
|
|
111
|
+
"name": "account_user_id_user_id_fk",
|
|
112
|
+
"tableFrom": "account",
|
|
113
|
+
"tableTo": "user",
|
|
114
|
+
"columnsFrom": ["user_id"],
|
|
115
|
+
"columnsTo": ["id"],
|
|
116
|
+
"onDelete": "cascade",
|
|
117
|
+
"onUpdate": "no action"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
"compositePrimaryKeys": {},
|
|
121
|
+
"uniqueConstraints": {},
|
|
122
|
+
"checkConstraints": {}
|
|
123
|
+
},
|
|
124
|
+
"session": {
|
|
125
|
+
"name": "session",
|
|
126
|
+
"columns": {
|
|
127
|
+
"id": {
|
|
128
|
+
"name": "id",
|
|
129
|
+
"type": "text",
|
|
130
|
+
"primaryKey": true,
|
|
131
|
+
"notNull": true,
|
|
132
|
+
"autoincrement": false
|
|
133
|
+
},
|
|
134
|
+
"expires_at": {
|
|
135
|
+
"name": "expires_at",
|
|
136
|
+
"type": "integer",
|
|
137
|
+
"primaryKey": false,
|
|
138
|
+
"notNull": true,
|
|
139
|
+
"autoincrement": false
|
|
140
|
+
},
|
|
141
|
+
"token": {
|
|
142
|
+
"name": "token",
|
|
143
|
+
"type": "text",
|
|
144
|
+
"primaryKey": false,
|
|
145
|
+
"notNull": true,
|
|
146
|
+
"autoincrement": false
|
|
147
|
+
},
|
|
148
|
+
"created_at": {
|
|
149
|
+
"name": "created_at",
|
|
150
|
+
"type": "integer",
|
|
151
|
+
"primaryKey": false,
|
|
152
|
+
"notNull": true,
|
|
153
|
+
"autoincrement": false
|
|
154
|
+
},
|
|
155
|
+
"updated_at": {
|
|
156
|
+
"name": "updated_at",
|
|
157
|
+
"type": "integer",
|
|
158
|
+
"primaryKey": false,
|
|
159
|
+
"notNull": true,
|
|
160
|
+
"autoincrement": false
|
|
161
|
+
},
|
|
162
|
+
"ip_address": {
|
|
163
|
+
"name": "ip_address",
|
|
164
|
+
"type": "text",
|
|
165
|
+
"primaryKey": false,
|
|
166
|
+
"notNull": false,
|
|
167
|
+
"autoincrement": false
|
|
168
|
+
},
|
|
169
|
+
"user_agent": {
|
|
170
|
+
"name": "user_agent",
|
|
171
|
+
"type": "text",
|
|
172
|
+
"primaryKey": false,
|
|
173
|
+
"notNull": false,
|
|
174
|
+
"autoincrement": false
|
|
175
|
+
},
|
|
176
|
+
"user_id": {
|
|
177
|
+
"name": "user_id",
|
|
178
|
+
"type": "text",
|
|
179
|
+
"primaryKey": false,
|
|
180
|
+
"notNull": true,
|
|
181
|
+
"autoincrement": false
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
"indexes": {
|
|
185
|
+
"session_token_unique": {
|
|
186
|
+
"name": "session_token_unique",
|
|
187
|
+
"columns": ["token"],
|
|
188
|
+
"isUnique": true
|
|
189
|
+
},
|
|
190
|
+
"session_user_id_idx": {
|
|
191
|
+
"name": "session_user_id_idx",
|
|
192
|
+
"columns": ["user_id"],
|
|
193
|
+
"isUnique": false
|
|
194
|
+
}
|
|
195
|
+
},
|
|
196
|
+
"foreignKeys": {
|
|
197
|
+
"session_user_id_user_id_fk": {
|
|
198
|
+
"name": "session_user_id_user_id_fk",
|
|
199
|
+
"tableFrom": "session",
|
|
200
|
+
"tableTo": "user",
|
|
201
|
+
"columnsFrom": ["user_id"],
|
|
202
|
+
"columnsTo": ["id"],
|
|
203
|
+
"onDelete": "cascade",
|
|
204
|
+
"onUpdate": "no action"
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
"compositePrimaryKeys": {},
|
|
208
|
+
"uniqueConstraints": {},
|
|
209
|
+
"checkConstraints": {}
|
|
210
|
+
},
|
|
211
|
+
"user": {
|
|
212
|
+
"name": "user",
|
|
213
|
+
"columns": {
|
|
214
|
+
"id": {
|
|
215
|
+
"name": "id",
|
|
216
|
+
"type": "text",
|
|
217
|
+
"primaryKey": true,
|
|
218
|
+
"notNull": true,
|
|
219
|
+
"autoincrement": false
|
|
220
|
+
},
|
|
221
|
+
"name": {
|
|
222
|
+
"name": "name",
|
|
223
|
+
"type": "text",
|
|
224
|
+
"primaryKey": false,
|
|
225
|
+
"notNull": true,
|
|
226
|
+
"autoincrement": false
|
|
227
|
+
},
|
|
228
|
+
"email": {
|
|
229
|
+
"name": "email",
|
|
230
|
+
"type": "text",
|
|
231
|
+
"primaryKey": false,
|
|
232
|
+
"notNull": true,
|
|
233
|
+
"autoincrement": false
|
|
234
|
+
},
|
|
235
|
+
"email_verified": {
|
|
236
|
+
"name": "email_verified",
|
|
237
|
+
"type": "integer",
|
|
238
|
+
"primaryKey": false,
|
|
239
|
+
"notNull": true,
|
|
240
|
+
"autoincrement": false,
|
|
241
|
+
"default": false
|
|
242
|
+
},
|
|
243
|
+
"image": {
|
|
244
|
+
"name": "image",
|
|
245
|
+
"type": "text",
|
|
246
|
+
"primaryKey": false,
|
|
247
|
+
"notNull": false,
|
|
248
|
+
"autoincrement": false
|
|
249
|
+
},
|
|
250
|
+
"created_at": {
|
|
251
|
+
"name": "created_at",
|
|
252
|
+
"type": "integer",
|
|
253
|
+
"primaryKey": false,
|
|
254
|
+
"notNull": true,
|
|
255
|
+
"autoincrement": false
|
|
256
|
+
},
|
|
257
|
+
"updated_at": {
|
|
258
|
+
"name": "updated_at",
|
|
259
|
+
"type": "integer",
|
|
260
|
+
"primaryKey": false,
|
|
261
|
+
"notNull": true,
|
|
262
|
+
"autoincrement": false
|
|
263
|
+
}
|
|
264
|
+
},
|
|
265
|
+
"indexes": {
|
|
266
|
+
"user_email_unique": {
|
|
267
|
+
"name": "user_email_unique",
|
|
268
|
+
"columns": ["email"],
|
|
269
|
+
"isUnique": true
|
|
270
|
+
}
|
|
271
|
+
},
|
|
272
|
+
"foreignKeys": {},
|
|
273
|
+
"compositePrimaryKeys": {},
|
|
274
|
+
"uniqueConstraints": {},
|
|
275
|
+
"checkConstraints": {}
|
|
276
|
+
},
|
|
277
|
+
"verification": {
|
|
278
|
+
"name": "verification",
|
|
279
|
+
"columns": {
|
|
280
|
+
"id": {
|
|
281
|
+
"name": "id",
|
|
282
|
+
"type": "text",
|
|
283
|
+
"primaryKey": true,
|
|
284
|
+
"notNull": true,
|
|
285
|
+
"autoincrement": false
|
|
286
|
+
},
|
|
287
|
+
"identifier": {
|
|
288
|
+
"name": "identifier",
|
|
289
|
+
"type": "text",
|
|
290
|
+
"primaryKey": false,
|
|
291
|
+
"notNull": true,
|
|
292
|
+
"autoincrement": false
|
|
293
|
+
},
|
|
294
|
+
"value": {
|
|
295
|
+
"name": "value",
|
|
296
|
+
"type": "text",
|
|
297
|
+
"primaryKey": false,
|
|
298
|
+
"notNull": true,
|
|
299
|
+
"autoincrement": false
|
|
300
|
+
},
|
|
301
|
+
"expires_at": {
|
|
302
|
+
"name": "expires_at",
|
|
303
|
+
"type": "integer",
|
|
304
|
+
"primaryKey": false,
|
|
305
|
+
"notNull": true,
|
|
306
|
+
"autoincrement": false
|
|
307
|
+
},
|
|
308
|
+
"created_at": {
|
|
309
|
+
"name": "created_at",
|
|
310
|
+
"type": "integer",
|
|
311
|
+
"primaryKey": false,
|
|
312
|
+
"notNull": true,
|
|
313
|
+
"autoincrement": false
|
|
314
|
+
},
|
|
315
|
+
"updated_at": {
|
|
316
|
+
"name": "updated_at",
|
|
317
|
+
"type": "integer",
|
|
318
|
+
"primaryKey": false,
|
|
319
|
+
"notNull": true,
|
|
320
|
+
"autoincrement": false
|
|
321
|
+
}
|
|
322
|
+
},
|
|
323
|
+
"indexes": {
|
|
324
|
+
"verification_identifier_idx": {
|
|
325
|
+
"name": "verification_identifier_idx",
|
|
326
|
+
"columns": ["identifier"],
|
|
327
|
+
"isUnique": false
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
"foreignKeys": {},
|
|
331
|
+
"compositePrimaryKeys": {},
|
|
332
|
+
"uniqueConstraints": {},
|
|
333
|
+
"checkConstraints": {}
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
"views": {},
|
|
337
|
+
"enums": {},
|
|
338
|
+
"_meta": {
|
|
339
|
+
"schemas": {},
|
|
340
|
+
"tables": {},
|
|
341
|
+
"columns": {}
|
|
342
|
+
},
|
|
343
|
+
"internal": {
|
|
344
|
+
"indexes": {}
|
|
345
|
+
}
|
|
346
|
+
}
|