anhedral 0.24.0 → 0.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/assets/launch/AGENTS.md.txt +7 -0
- package/assets/launch/README.md.txt +40 -0
- package/assets/launch/backend-vite.config.ts.txt +18 -0
- package/assets/launch/home.tsx.txt +2 -1
- package/assets/launch/root.tsx.txt +38 -5
- package/assets/launch/router.tsx.txt +3 -2
- package/assets/launch/sign-in.tsx.txt +2 -1
- package/assets/launch/storage-page.tsx.txt +1 -0
- package/assets/launch/styles.css.txt +55 -16
- package/assets/launch/styling-tokens.cjs +45 -0
- package/assets/launch/vite.config.ts.txt +13 -0
- package/assets/stack/api-eslint.config.mjs.txt +2 -0
- package/assets/stack/api-index.ts.txt +1 -0
- package/assets/stack/api-proxy.ts.txt +112 -0
- package/assets/stack/auth-routes.ts.txt +3 -1
- package/assets/stack/auth.ts.txt +5 -4
- package/assets/stack/base-eslint.js.txt +16 -0
- package/assets/stack/billing-mode.ts.txt +2 -0
- package/assets/stack/billing-providers.ts.txt +8 -0
- package/assets/stack/db-index.ts.txt +7 -0
- package/assets/stack/db-migrate.mjs.txt +23 -0
- package/assets/stack/drizzle.config.ts.txt +2 -0
- package/assets/stack/entitlement-guard.ts.txt +2 -0
- package/assets/stack/entitlements.ts.txt +3 -1
- package/assets/stack/payment.test.mjs.txt +7 -1
- package/assets/stack/security.ts.txt +2 -0
- package/assets/stack/shared-eslint.config.mjs.txt +6 -0
- package/assets/stack/storage.ts.txt +3 -1
- package/assets/stack/stripe.ts.txt +4 -2
- package/dist/cli-output.js +1 -1
- package/dist/composition/recipes.d.ts +1 -1
- package/dist/composition/recipes.js +51 -56
- package/dist/dependencies.d.ts +0 -6
- package/dist/dependencies.js +0 -1
- package/dist/launch.d.ts +1 -1
- package/dist/launch.js +25 -103
- package/dist/render.d.ts +0 -10
- package/dist/render.js +1 -38
- package/dist/scaffold/bootstrap.d.ts +1 -2
- package/dist/scaffold/bootstrap.js +4 -8
- package/dist/scaffold/files.d.ts +12 -24
- package/dist/scaffold/files.js +9 -103
- package/dist/scaffold/styling.d.ts +2 -4
- package/dist/scaffold/styling.js +46 -69
- package/dist/scaffold/tanstack.d.ts +1 -1
- package/dist/scaffold/tanstack.js +22 -37
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/software-factory.md +1 -1
- package/package.json +4 -2
- package/dist/api-proxy.d.ts +0 -1
- package/dist/api-proxy.js +0 -48
package/README.md
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
Build an app one addition at a time. Generated applications are editable source. Start with a TanStack Start web app and ShadCN components. Add a backend when you need an API, authentication, or a database. Then choose storage, payments, or both.
|
|
7
7
|
|
|
8
8
|
<picture>
|
|
9
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/anhedral/anhedral-cli/
|
|
10
|
-
<img src="https://raw.githubusercontent.com/anhedral/anhedral-cli/
|
|
9
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/anhedral/anhedral-cli/v0.24.1/docs/assets/anhedral-stack.png">
|
|
10
|
+
<img src="https://raw.githubusercontent.com/anhedral/anhedral-cli/v0.24.1/docs/assets/anhedral-stack-light.png" alt="The CLI creates a TanStack Start web app. The optional backend supports private file storage and subscription payments. An Expo client with Anhedral UI is upcoming.">
|
|
11
11
|
</picture>
|
|
12
12
|
|
|
13
13
|
**Upcoming** — `pnpm dlx anhedral@latest add cross-platform` will add an Expo client with Anhedral UI.
|
|
@@ -31,7 +31,7 @@ pnpm dlx anhedral@latest add storage
|
|
|
31
31
|
pnpm dlx anhedral@latest add payment
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
Run `pnpm dev` in the project directory to start the app. If you added services, configure them first. [Service setup](docs/capabilities.md) · [Source snapshot for each stage](https://github.com/anhedral/anhedral-cli/tree/
|
|
34
|
+
Run `pnpm dev` in the project directory to start the app. If you added services, configure them first. [Service setup](docs/capabilities.md) · [Source snapshot for each stage](https://github.com/anhedral/anhedral-cli/tree/v0.24.1/examples)
|
|
35
35
|
|
|
36
36
|
Upgrading from 0.22.1? Replace `add r2` with `add storage` and `add stripe` with `add payment`. Existing projects keep their R2 and Stripe configuration.
|
|
37
37
|
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
# Application conventions
|
|
2
|
+
|
|
3
|
+
- Edit product pages in `apps/web/src/routes` and shared UI in `apps/web/src/components/ui`. Keep the ShadCN license with its components.
|
|
4
|
+
- With the backend installed, put custom API routes in `apps/api/src/index.ts` and database schema in `packages/db/src`. Web server functions call the API through its service binding. Keep identity, secrets, and database and storage access in the API.
|
|
5
|
+
- Review auth configuration before enabling a sign-in method. Generate and review SQL before applying it to an explicitly selected database. Builds, tests, and startup must leave configured databases untouched.
|
|
6
|
+
- Preview changes to CLI-managed adapters with `pnpm dlx anhedral@latest stack update --dry-run --human`. Preserve existing application edits.
|
|
7
|
+
- Run `pnpm check` and `pnpm audit:deps` before shipping.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# __APP_NAME__
|
|
2
|
+
|
|
3
|
+
A TanStack Start web app with editable ShadCN components.
|
|
4
|
+
|
|
5
|
+
## Run locally
|
|
6
|
+
|
|
7
|
+
Use the Node.js and pnpm versions declared in `package.json`. If you skipped installation during setup, run `pnpm install` first.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm dev
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Open http://localhost:3000. Edit `apps/web/src/routes/index.tsx` for the home page and `apps/web/src/routes/__root.tsx` for the shared layout. UI components live in `apps/web/src/components/ui`. You can use any UI library.
|
|
14
|
+
|
|
15
|
+
## Check your changes
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
pnpm check # Lint, typecheck, test, and build
|
|
19
|
+
pnpm audit:deps # Audit installed dependencies
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Add services
|
|
23
|
+
|
|
24
|
+
Run the backend command first, then add storage or payment as needed.
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
pnpm dlx anhedral@latest add backend # Hono, Better Auth, and Drizzle/D1
|
|
28
|
+
pnpm dlx anhedral@latest add storage # Private files on R2
|
|
29
|
+
pnpm dlx anhedral@latest add payment # Stripe subscriptions
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
After adding a service, follow the environment and migration instructions before running it locally. [Service setup](https://github.com/anhedral/anhedral-cli/blob/v__CLI_VERSION__/docs/capabilities.md#local-setup-and-validation)
|
|
33
|
+
|
|
34
|
+
## Update the stack
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
pnpm dlx anhedral@latest stack update --dry-run --human
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Review the diff and run the version-pinned apply command it prints. Then run `pnpm install` and `pnpm check`.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import { cloudflare } from '@cloudflare/vite-plugin';
|
|
4
|
+
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
|
|
5
|
+
import react from '@vitejs/plugin-react';
|
|
6
|
+
export default defineConfig(({ command }) => ({
|
|
7
|
+
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
|
|
8
|
+
plugins: [
|
|
9
|
+
cloudflare({
|
|
10
|
+
viteEnvironment: { name: 'ssr' },
|
|
11
|
+
auxiliaryWorkers: command === 'serve' ? [{ configPath: '../api/wrangler.jsonc' }] : [],
|
|
12
|
+
persistState: { path: fileURLToPath(new URL('../api/.wrangler/state', import.meta.url)) },
|
|
13
|
+
remoteBindings: false,
|
|
14
|
+
}),
|
|
15
|
+
tanstackStart({ server: { entry: './server.ts' } }),
|
|
16
|
+
react(),
|
|
17
|
+
],
|
|
18
|
+
}));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { starterTitle } from '../starter';
|
|
2
1
|
import { createFileRoute, useRouter } from '@tanstack/react-router';
|
|
3
2
|
import { createServerFn } from '@tanstack/react-start';
|
|
3
|
+
|
|
4
|
+
import { starterTitle } from '../starter';
|
|
4
5
|
import { Button } from '@/components/ui/button';
|
|
5
6
|
|
|
6
7
|
const applicationStatus = createServerFn({ method: 'GET' }).handler(async ({ context }) => {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import { starterTitle } from '../starter';
|
|
2
1
|
import { createRootRoute, HeadContent, Link, Outlet, Scripts } from '@tanstack/react-router';
|
|
3
2
|
import type { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
import { starterTitle } from '../starter';
|
|
5
|
+
|
|
4
6
|
import '../styles.css';
|
|
5
7
|
|
|
6
8
|
export const Route = createRootRoute({
|
|
@@ -13,14 +15,45 @@ export const Route = createRootRoute({
|
|
|
13
15
|
],
|
|
14
16
|
}),
|
|
15
17
|
component: Root,
|
|
16
|
-
notFoundComponent: () =>
|
|
17
|
-
|
|
18
|
+
notFoundComponent: () => (
|
|
19
|
+
<section className="stack">
|
|
20
|
+
<h1>Page not found</h1>
|
|
21
|
+
<Link to="/">Return home</Link>
|
|
22
|
+
</section>
|
|
23
|
+
),
|
|
24
|
+
errorComponent: ({ reset }) => (
|
|
25
|
+
<section className="stack">
|
|
26
|
+
<h1>Unable to load this page</h1>
|
|
27
|
+
<button type="button" onClick={reset}>
|
|
28
|
+
Try again
|
|
29
|
+
</button>
|
|
30
|
+
</section>
|
|
31
|
+
),
|
|
18
32
|
});
|
|
19
33
|
|
|
20
34
|
function Root() {
|
|
21
|
-
return
|
|
35
|
+
return (
|
|
36
|
+
<Document>
|
|
37
|
+
<main>
|
|
38
|
+
<nav aria-label="Main">
|
|
39
|
+
<Link to="/">Home</Link>
|
|
40
|
+
</nav>
|
|
41
|
+
<Outlet />
|
|
42
|
+
</main>
|
|
43
|
+
</Document>
|
|
44
|
+
);
|
|
22
45
|
}
|
|
23
46
|
|
|
24
47
|
function Document({ children }: { children: ReactNode }) {
|
|
25
|
-
return
|
|
48
|
+
return (
|
|
49
|
+
<html lang="en">
|
|
50
|
+
<head>
|
|
51
|
+
<HeadContent />
|
|
52
|
+
</head>
|
|
53
|
+
<body>
|
|
54
|
+
{children}
|
|
55
|
+
<Scripts />
|
|
56
|
+
</body>
|
|
57
|
+
</html>
|
|
58
|
+
);
|
|
26
59
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type {} from '@tanstack/react-start';
|
|
2
1
|
import { createRouter } from '@tanstack/react-router';
|
|
3
|
-
import {
|
|
2
|
+
import type {} from '@tanstack/react-start';
|
|
3
|
+
|
|
4
4
|
import type { ApplicationContext } from './lib/request-context';
|
|
5
|
+
import { routeTree } from './routeTree.gen';
|
|
5
6
|
|
|
6
7
|
export function getRouter() {
|
|
7
8
|
return createRouter({ routeTree, scrollRestoration: true });
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { createFileRoute } from '@tanstack/react-router';
|
|
2
2
|
import { useState, type FormEvent } from 'react';
|
|
3
|
-
|
|
3
|
+
|
|
4
4
|
import { Button } from '@/components/ui/button';
|
|
5
5
|
import { Input } from '@/components/ui/input';
|
|
6
6
|
import { Label } from '@/components/ui/label';
|
|
7
|
+
import { authClient } from '@/lib/auth-client';
|
|
7
8
|
|
|
8
9
|
export const Route = createFileRoute('/sign-in')({ component: Account });
|
|
9
10
|
|
|
@@ -1,19 +1,58 @@
|
|
|
1
1
|
@import 'tailwindcss';
|
|
2
2
|
@import '@workspace/styling/globals.css';
|
|
3
3
|
@theme inline {
|
|
4
|
-
--color-background: hsl(var(--background));
|
|
5
|
-
--color-
|
|
6
|
-
--color-
|
|
7
|
-
--color-
|
|
8
|
-
--color-
|
|
9
|
-
--color-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
4
|
+
--color-background: hsl(var(--background));
|
|
5
|
+
--color-foreground: hsl(var(--foreground));
|
|
6
|
+
--color-primary: hsl(var(--primary));
|
|
7
|
+
--color-primary-foreground: hsl(var(--primary-foreground));
|
|
8
|
+
--color-secondary: hsl(var(--secondary));
|
|
9
|
+
--color-secondary-foreground: hsl(var(--secondary-foreground));
|
|
10
|
+
--color-muted: hsl(var(--muted));
|
|
11
|
+
--color-muted-foreground: hsl(var(--muted-foreground));
|
|
12
|
+
--color-border: hsl(var(--border));
|
|
13
|
+
--color-input: hsl(var(--input));
|
|
14
|
+
--color-ring: hsl(var(--ring));
|
|
15
|
+
--color-destructive: hsl(var(--destructive));
|
|
16
|
+
--radius-md: var(--radius);
|
|
17
|
+
--radius-lg: calc(var(--radius) + 2px);
|
|
18
|
+
}
|
|
19
|
+
* {
|
|
20
|
+
box-sizing: border-box;
|
|
21
|
+
}
|
|
22
|
+
body {
|
|
23
|
+
margin: 0;
|
|
24
|
+
background: hsl(var(--background));
|
|
25
|
+
color: hsl(var(--foreground));
|
|
26
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
27
|
+
}
|
|
28
|
+
main {
|
|
29
|
+
max-width: 64rem;
|
|
30
|
+
margin: 0 auto;
|
|
31
|
+
padding: 4rem 1.5rem;
|
|
32
|
+
}
|
|
33
|
+
nav {
|
|
34
|
+
display: flex;
|
|
35
|
+
gap: 1rem;
|
|
36
|
+
margin-bottom: 3rem;
|
|
37
|
+
}
|
|
38
|
+
.stack,
|
|
39
|
+
form {
|
|
40
|
+
display: grid;
|
|
41
|
+
gap: 1rem;
|
|
42
|
+
}
|
|
43
|
+
form {
|
|
44
|
+
width: 100%;
|
|
45
|
+
max-width: 26rem;
|
|
46
|
+
}
|
|
47
|
+
h1 {
|
|
48
|
+
font-size: 2rem;
|
|
49
|
+
font-weight: 600;
|
|
50
|
+
line-height: 1.2;
|
|
51
|
+
letter-spacing: -0.025em;
|
|
52
|
+
}
|
|
53
|
+
a {
|
|
54
|
+
color: inherit;
|
|
55
|
+
}
|
|
56
|
+
.muted {
|
|
57
|
+
color: hsl(var(--muted-foreground));
|
|
58
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
exports.light = {
|
|
2
|
+
'--background': '0 0% 100%',
|
|
3
|
+
'--foreground': '0 0% 9%',
|
|
4
|
+
'--card': '0 0% 100%',
|
|
5
|
+
'--card-foreground': '0 0% 9%',
|
|
6
|
+
'--popover': '0 0% 100%',
|
|
7
|
+
'--popover-foreground': '0 0% 9%',
|
|
8
|
+
'--primary': '0 0% 9%',
|
|
9
|
+
'--primary-foreground': '0 0% 98%',
|
|
10
|
+
'--secondary': '0 0% 96.1%',
|
|
11
|
+
'--secondary-foreground': '0 0% 9%',
|
|
12
|
+
'--muted': '0 0% 96.1%',
|
|
13
|
+
'--muted-foreground': '0 0% 45.1%',
|
|
14
|
+
'--accent': '0 0% 96.1%',
|
|
15
|
+
'--accent-foreground': '0 0% 9%',
|
|
16
|
+
'--destructive': '0 84.2% 60.2%',
|
|
17
|
+
'--destructive-foreground': '0 0% 98%',
|
|
18
|
+
'--border': '0 0% 89.8%',
|
|
19
|
+
'--input': '0 0% 89.8%',
|
|
20
|
+
'--ring': '0 0% 63.9%',
|
|
21
|
+
'--radius': '0.5rem',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
exports.dark = {
|
|
25
|
+
...exports.light,
|
|
26
|
+
'--background': '0 0% 9%',
|
|
27
|
+
'--foreground': '0 0% 98%',
|
|
28
|
+
'--card': '0 0% 9%',
|
|
29
|
+
'--card-foreground': '0 0% 98%',
|
|
30
|
+
'--popover': '0 0% 9%',
|
|
31
|
+
'--popover-foreground': '0 0% 98%',
|
|
32
|
+
'--primary': '0 0% 98%',
|
|
33
|
+
'--primary-foreground': '0 0% 9%',
|
|
34
|
+
'--secondary': '0 0% 14.9%',
|
|
35
|
+
'--secondary-foreground': '0 0% 98%',
|
|
36
|
+
'--muted': '0 0% 14.9%',
|
|
37
|
+
'--muted-foreground': '0 0% 63.9%',
|
|
38
|
+
'--accent': '0 0% 14.9%',
|
|
39
|
+
'--accent-foreground': '0 0% 98%',
|
|
40
|
+
'--destructive': '0 70.9% 59.4%',
|
|
41
|
+
'--border': '0 0% 14.9%',
|
|
42
|
+
'--input': '0 0% 14.9%',
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.spacing = { small: 4, medium: 8, large: 16 };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import { cloudflare } from '@cloudflare/vite-plugin';
|
|
4
|
+
import { tanstackStart } from '@tanstack/react-start/plugin/vite';
|
|
5
|
+
import react from '@vitejs/plugin-react';
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },
|
|
8
|
+
plugins: [
|
|
9
|
+
cloudflare({ viteEnvironment: { name: 'ssr' }, remoteBindings: false }),
|
|
10
|
+
tanstackStart({ server: { entry: './server.ts' } }),
|
|
11
|
+
react(),
|
|
12
|
+
],
|
|
13
|
+
});
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
export interface ApiBinding {
|
|
2
|
+
fetch(request: Request): Promise<Response>;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
type Options = {
|
|
6
|
+
binding?: ApiBinding;
|
|
7
|
+
development: boolean;
|
|
8
|
+
devOrigin?: string;
|
|
9
|
+
send?: typeof fetch;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function developmentOrigin(configured?: string): string {
|
|
13
|
+
const url = new URL(configured || 'http://127.0.0.1:8787');
|
|
14
|
+
const loopback = new Set(['127.0.0.1', 'localhost', '[::1]']);
|
|
15
|
+
const invalid = [
|
|
16
|
+
url.protocol !== 'http:',
|
|
17
|
+
!loopback.has(url.hostname),
|
|
18
|
+
url.username,
|
|
19
|
+
url.password,
|
|
20
|
+
url.pathname !== '/',
|
|
21
|
+
url.search,
|
|
22
|
+
url.hash,
|
|
23
|
+
];
|
|
24
|
+
if (invalid.some(Boolean)) throw Error('API_INTERNAL_URL must be a loopback HTTP origin.');
|
|
25
|
+
return url.origin;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function backendOrigin(options: Options): string {
|
|
29
|
+
if (options.development) return developmentOrigin(options.devOrigin);
|
|
30
|
+
if ([!options.binding, options.devOrigin].some(Boolean))
|
|
31
|
+
throw Error('Production requires the API service binding.');
|
|
32
|
+
return 'https://api.internal';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function apiTarget(request: Request, origin: string): URL {
|
|
36
|
+
const url = new URL(request.url);
|
|
37
|
+
if (!/^\/api(?:\/|$)/.test(url.pathname)) throw Error('Unexpected API path.');
|
|
38
|
+
return new URL(url.pathname + url.search, origin);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function forwardedHeaders(request: Request): Headers {
|
|
42
|
+
const headers = new Headers();
|
|
43
|
+
for (const name of [
|
|
44
|
+
'accept',
|
|
45
|
+
'content-type',
|
|
46
|
+
'cookie',
|
|
47
|
+
'origin',
|
|
48
|
+
'authorization',
|
|
49
|
+
'sec-fetch-site',
|
|
50
|
+
'expo-origin',
|
|
51
|
+
'idempotency-key',
|
|
52
|
+
'stripe-signature',
|
|
53
|
+
'last-event-id',
|
|
54
|
+
]) {
|
|
55
|
+
const value = request.headers.get(name);
|
|
56
|
+
if (value) headers.set(name, value);
|
|
57
|
+
}
|
|
58
|
+
return headers;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function upstreamRequest(request: Request, target: URL): Request {
|
|
62
|
+
const settings: RequestInit & { duplex?: 'half' } = {
|
|
63
|
+
method: request.method,
|
|
64
|
+
headers: forwardedHeaders(request),
|
|
65
|
+
redirect: 'manual',
|
|
66
|
+
signal: AbortSignal.any([
|
|
67
|
+
request.signal,
|
|
68
|
+
AbortSignal.timeout(
|
|
69
|
+
request.headers.get('accept')?.includes('text/event-stream') ? 35000 : 15000,
|
|
70
|
+
),
|
|
71
|
+
]),
|
|
72
|
+
};
|
|
73
|
+
if (!['GET', 'HEAD'].includes(request.method)) {
|
|
74
|
+
settings.body = request.body;
|
|
75
|
+
settings.duplex = 'half';
|
|
76
|
+
}
|
|
77
|
+
return new Request(target, settings);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function privateResponse(response: Response, development: boolean): Response {
|
|
81
|
+
const headers = new Headers(response.headers);
|
|
82
|
+
for (const name of [
|
|
83
|
+
'connection',
|
|
84
|
+
'transfer-encoding',
|
|
85
|
+
'access-control-allow-origin',
|
|
86
|
+
'access-control-allow-credentials',
|
|
87
|
+
])
|
|
88
|
+
headers.delete(name);
|
|
89
|
+
// Node fetch already decoded the local HTTP response. The server must frame/compress
|
|
90
|
+
// those decoded bytes itself; the sidecar's wire headers no longer describe them.
|
|
91
|
+
if (development) {
|
|
92
|
+
headers.delete('content-encoding');
|
|
93
|
+
headers.delete('content-length');
|
|
94
|
+
}
|
|
95
|
+
headers.set('cache-control', 'private, no-store');
|
|
96
|
+
return new Response(response.body, { status: response.status, headers });
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export async function proxyApi(request: Request, options: Options): Promise<Response> {
|
|
100
|
+
try {
|
|
101
|
+
const upstream = upstreamRequest(request, apiTarget(request, backendOrigin(options)));
|
|
102
|
+
const response = options.development
|
|
103
|
+
? await (options.send ?? fetch)(upstream)
|
|
104
|
+
: await options.binding!.fetch(upstream);
|
|
105
|
+
return privateResponse(response, options.development);
|
|
106
|
+
} catch {
|
|
107
|
+
return Response.json(
|
|
108
|
+
{ error: 'API unavailable' },
|
|
109
|
+
{ status: 503, headers: { 'cache-control': 'private, no-store' } },
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
|
+
|
|
2
3
|
import { createAuth, authConfiguration } from '../auth';
|
|
3
|
-
import { requireSession } from '../security';
|
|
4
4
|
import type { AppEnv } from '../environment';
|
|
5
|
+
import { requireSession } from '../security';
|
|
6
|
+
|
|
5
7
|
export const authRoutes = new Hono<AppEnv>();
|
|
6
8
|
authRoutes.on(['GET', 'POST'], '/auth/*', (c) => {
|
|
7
9
|
if (!authConfiguration.safeParse(c.env).success)
|
package/assets/stack/auth.ts.txt
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { z } from 'zod';
|
|
2
|
-
import { betterAuth } from 'better-auth/minimal';
|
|
3
1
|
import { drizzleAdapter } from '@better-auth/drizzle-adapter';
|
|
4
|
-
import { platformAuthPlugins } from './auth-platform';
|
|
5
|
-
import { bearer } from 'better-auth/plugins/bearer';
|
|
6
2
|
import { createDatabase } from '@workspace/db';
|
|
7
3
|
import * as schema from '@workspace/db/schema';
|
|
4
|
+
import { betterAuth } from 'better-auth/minimal';
|
|
5
|
+
import { bearer } from 'better-auth/plugins/bearer';
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
|
|
8
8
|
import { authFeatures } from './auth-features';
|
|
9
|
+
import { platformAuthPlugins } from './auth-platform';
|
|
9
10
|
import type { AppEnv } from './environment';
|
|
10
11
|
|
|
11
12
|
export const authConfiguration = z.object({
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import parser from '@typescript-eslint/parser';
|
|
2
|
+
import plugin from '@typescript-eslint/eslint-plugin';
|
|
3
|
+
export const config = [
|
|
4
|
+
{ ignores: ['dist/**', '.output/**', '.wrangler/**', 'worker-configuration.d.ts'] },
|
|
5
|
+
{
|
|
6
|
+
files: ['**/*.{ts,tsx,cts,mts}'],
|
|
7
|
+
languageOptions: { parser, parserOptions: { ecmaFeatures: { jsx: true } } },
|
|
8
|
+
plugins: { '@typescript-eslint': plugin },
|
|
9
|
+
rules: {
|
|
10
|
+
...plugin.configs.recommended.rules,
|
|
11
|
+
'no-undef': 'off',
|
|
12
|
+
'no-unused-vars': 'off',
|
|
13
|
+
'@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
];
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { AppEnv } from './environment';
|
|
2
|
+
import { stripeEntitled } from './features/stripe';
|
|
3
|
+
|
|
4
|
+
type EntitlementCheck = (env: AppEnv['Bindings'], userId: string) => Promise<boolean>;
|
|
5
|
+
|
|
6
|
+
export const billingProviders: Record<string, EntitlementCheck> = {
|
|
7
|
+
stripe: stripeEntitled,
|
|
8
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
const args = process.argv.slice(2);
|
|
4
|
+
if (args.length > 1 || args.some((v) => !['--local', '--remote'].includes(v)))
|
|
5
|
+
throw Error('Use --local or explicitly --remote.');
|
|
6
|
+
if (!process.env.npm_execpath) throw Error('Run through pnpm db:migrate.');
|
|
7
|
+
const cwd = fileURLToPath(new URL('../../../apps/api/', import.meta.url));
|
|
8
|
+
const result = spawnSync(
|
|
9
|
+
process.execPath,
|
|
10
|
+
[
|
|
11
|
+
process.env.npm_execpath,
|
|
12
|
+
'exec',
|
|
13
|
+
'wrangler',
|
|
14
|
+
'd1',
|
|
15
|
+
'migrations',
|
|
16
|
+
'apply',
|
|
17
|
+
'DB',
|
|
18
|
+
args[0] ?? '--local',
|
|
19
|
+
],
|
|
20
|
+
{ cwd, stdio: 'inherit', shell: false },
|
|
21
|
+
);
|
|
22
|
+
if (result.error) throw result.error;
|
|
23
|
+
process.exitCode = result.status ?? 1;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { type MiddlewareHandler } from 'hono';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
|
|
3
4
|
import { billingProviders } from './billing-providers';
|
|
4
5
|
import type { AppEnv } from './environment';
|
|
6
|
+
|
|
5
7
|
const policy = z.enum(['stripe', 'revenuecat', 'either']);
|
|
6
8
|
function selectedProviders(env: AppEnv['Bindings']) {
|
|
7
9
|
const selected = policy.parse(env.BILLING_PROVIDER);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import { requireEntitlement } from '../entitlement-guard';
|
|
4
4
|
import type { AppEnv } from '../environment';
|
|
5
|
+
import { requireSession } from '../security';
|
|
6
|
+
|
|
5
7
|
export const entitlementRoutes = new Hono<AppEnv>();
|
|
6
8
|
entitlementRoutes.get('/billing/access', requireSession, requireEntitlement, (c) =>
|
|
7
9
|
c.json({ allowed: true }),
|
|
@@ -20,7 +20,13 @@ test('reviewable local migrations support idempotent signed webhook delivery', a
|
|
|
20
20
|
const cli = join(dirname(require.resolve('drizzle-kit/api')), 'bin.cjs');
|
|
21
21
|
execFileSync(
|
|
22
22
|
process.execPath,
|
|
23
|
-
[
|
|
23
|
+
[
|
|
24
|
+
cli,
|
|
25
|
+
'generate',
|
|
26
|
+
'--dialect=sqlite',
|
|
27
|
+
'--schema=' + fileURLToPath(new URL('src/schema.ts', root)),
|
|
28
|
+
'--out=./drizzle',
|
|
29
|
+
],
|
|
24
30
|
{ cwd: work, stdio: 'pipe' },
|
|
25
31
|
);
|
|
26
32
|
const db = new DatabaseSync(':memory:');
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { MiddlewareHandler } from 'hono';
|
|
2
|
+
|
|
2
3
|
import { createAuth, authConfiguration } from './auth';
|
|
3
4
|
import type { AppEnv } from './environment';
|
|
5
|
+
|
|
4
6
|
const bearer = (headers: Headers) => (headers.get('authorization') ?? '').startsWith('Bearer ');
|
|
5
7
|
function sessionHeaders(request: Request) {
|
|
6
8
|
const headers = new Headers(request.headers);
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import type { AppEnv } from '../environment';
|
|
4
|
+
import { requireSession } from '../security';
|
|
5
|
+
|
|
4
6
|
export const storageRoutes = new Hono<AppEnv>();
|
|
5
7
|
storageRoutes.use('/files/*', requireSession);
|
|
6
8
|
storageRoutes.use('/files/:name', async (c, next) => {
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Hono } from 'hono';
|
|
2
|
-
import { z } from 'zod';
|
|
3
2
|
import Stripe from 'stripe';
|
|
4
|
-
import {
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
|
|
5
5
|
import { billingEnvironment } from '../billing-mode';
|
|
6
6
|
import type { AppEnv } from '../environment';
|
|
7
|
+
import { requireSession } from '../security';
|
|
8
|
+
|
|
7
9
|
export const stripeRoutes = new Hono<AppEnv>();
|
|
8
10
|
const client = (key: string) =>
|
|
9
11
|
new Stripe(key, {
|