anhedral 0.12.0 → 0.15.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.
Files changed (184) hide show
  1. package/README.md +35 -172
  2. package/assets/patches/audit-deps.mjs +12 -2
  3. package/assets/ui/LICENSE.shadcn +21 -0
  4. package/assets/ui/UPSTREAM.json +33 -0
  5. package/assets/ui/native/button.tsx +85 -0
  6. package/assets/ui/native/card.tsx +33 -0
  7. package/assets/ui/native/dialog.tsx +75 -0
  8. package/assets/ui/native/input.tsx +27 -0
  9. package/assets/ui/native/label.tsx +4 -0
  10. package/assets/ui/native/layout.tsx +26 -0
  11. package/assets/ui/native/text.tsx +20 -0
  12. package/assets/ui/native/theme-switcher.tsx +22 -0
  13. package/assets/ui/theme-storage.ts +25 -0
  14. package/assets/ui/theme.tsx +66 -0
  15. package/assets/ui/web/button.tsx +59 -0
  16. package/assets/ui/web/input.tsx +21 -0
  17. package/assets/ui/web/label.tsx +19 -0
  18. package/dist/capabilities.d.ts +5 -5
  19. package/dist/capabilities.js +3 -21
  20. package/dist/capability-contract.d.ts +3 -3
  21. package/dist/capability-contract.js +11 -39
  22. package/dist/cli-delivery.d.ts +1 -1
  23. package/dist/cli-delivery.js +5 -65
  24. package/dist/cli-output.js +3 -3
  25. package/dist/command-schema.js +35 -80
  26. package/dist/command.js +9 -11
  27. package/dist/delivery-evidence.d.ts +1 -1
  28. package/dist/delivery-evidence.js +7 -36
  29. package/dist/delivery.d.ts +2 -8
  30. package/dist/delivery.js +23 -102
  31. package/dist/dependencies.d.ts +12 -58
  32. package/dist/dependencies.js +67 -189
  33. package/dist/index.d.ts +1 -3
  34. package/dist/index.js +1 -3
  35. package/dist/inspector-model.d.ts +2 -2
  36. package/dist/integration-service-readers.d.ts +1 -2
  37. package/dist/integration-service-readers.js +3 -84
  38. package/dist/lifecycle-model.d.ts +1 -1
  39. package/dist/lifecycle-model.js +1 -1
  40. package/dist/mobile-delivery.d.ts +1 -1
  41. package/dist/mobile-delivery.js +4 -0
  42. package/dist/platforms/mobile.d.ts +1 -1
  43. package/dist/platforms/mobile.js +64 -114
  44. package/dist/platforms/web.d.ts +3 -0
  45. package/dist/platforms/web.js +299 -0
  46. package/dist/project-config.d.ts +1 -1
  47. package/dist/project-config.js +0 -1
  48. package/dist/project-inspector.js +5 -36
  49. package/dist/project-state.d.ts +1 -3
  50. package/dist/project-state.js +6 -86
  51. package/dist/provider-auth.js +3 -32
  52. package/dist/provider-readiness.d.ts +1 -1
  53. package/dist/provider-readiness.js +5 -24
  54. package/dist/providers/adapters.js +9 -178
  55. package/dist/providers/api.d.ts +1 -1
  56. package/dist/providers/api.js +3 -3
  57. package/dist/providers/config.js +2 -48
  58. package/dist/providers/definitions.d.ts +1 -204
  59. package/dist/providers/definitions.js +0 -85
  60. package/dist/providers/provision.d.ts +1 -1
  61. package/dist/providers/receipts.js +1 -11
  62. package/dist/providers/recovery-verification.js +1 -61
  63. package/dist/providers/runtime.js +15 -35
  64. package/dist/providers/state.js +1 -7
  65. package/dist/provision.d.ts +5 -13
  66. package/dist/provision.js +4 -80
  67. package/dist/readiness.d.ts +1 -1
  68. package/dist/readiness.js +3 -6
  69. package/dist/registry/add.js +11 -38
  70. package/dist/registry/bootstrap.d.ts +3 -2
  71. package/dist/registry/bootstrap.js +4 -13
  72. package/dist/registry/commands.js +8 -10
  73. package/dist/registry/context.js +0 -1
  74. package/dist/registry/options.js +8 -26
  75. package/dist/registry/resolve.d.ts +3 -2
  76. package/dist/registry/resolve.js +26 -82
  77. package/dist/registry/types.d.ts +2 -7
  78. package/dist/registry/usage.js +2 -2
  79. package/dist/runtime-policy.d.ts +0 -2
  80. package/dist/runtime-policy.js +0 -13
  81. package/dist/scaffold/api.js +10 -2
  82. package/dist/scaffold/auth.d.ts +1 -2
  83. package/dist/scaffold/auth.js +57 -116
  84. package/dist/scaffold/backend.d.ts +2 -0
  85. package/dist/scaffold/backend.js +39 -0
  86. package/dist/scaffold/billing-config.d.ts +1 -0
  87. package/dist/scaffold/billing-config.js +73 -0
  88. package/dist/scaffold/billing-contracts.d.ts +2 -0
  89. package/dist/scaffold/billing-contracts.js +48 -0
  90. package/dist/scaffold/billing-providers.d.ts +1 -0
  91. package/dist/scaffold/billing-providers.js +249 -0
  92. package/dist/scaffold/billing-schema.d.ts +1 -0
  93. package/dist/scaffold/billing-schema.js +34 -0
  94. package/dist/scaffold/billing-security.d.ts +1 -0
  95. package/dist/scaffold/billing-security.js +46 -0
  96. package/dist/scaffold/billing-server.d.ts +1 -0
  97. package/dist/scaffold/billing-server.js +139 -0
  98. package/dist/scaffold/billing-store.d.ts +1 -0
  99. package/dist/scaffold/billing-store.js +72 -0
  100. package/dist/scaffold/billing.d.ts +2 -0
  101. package/dist/scaffold/billing.js +208 -0
  102. package/dist/scaffold/bootstrap.d.ts +2 -3
  103. package/dist/scaffold/bootstrap.js +37 -43
  104. package/dist/scaffold/compose.js +2 -12
  105. package/dist/scaffold/database.d.ts +1 -1
  106. package/dist/scaffold/database.js +20 -111
  107. package/dist/scaffold/documentation.d.ts +0 -1
  108. package/dist/scaffold/documentation.js +22 -82
  109. package/dist/scaffold/expo-auth.d.ts +3 -0
  110. package/dist/scaffold/expo-auth.js +203 -0
  111. package/dist/scaffold/expo-billing.d.ts +3 -0
  112. package/dist/scaffold/expo-billing.js +257 -0
  113. package/dist/scaffold/expo-runtime.d.ts +3 -0
  114. package/dist/scaffold/expo-runtime.js +43 -0
  115. package/dist/scaffold/integrations.d.ts +1 -2
  116. package/dist/scaffold/integrations.js +9 -5
  117. package/dist/scaffold/managed-email.d.ts +3 -0
  118. package/dist/scaffold/managed-email.js +47 -0
  119. package/dist/scaffold/native-ui.d.ts +2 -0
  120. package/dist/scaffold/native-ui.js +69 -0
  121. package/dist/scaffold/password-reset.d.ts +1 -0
  122. package/dist/scaffold/password-reset.js +99 -0
  123. package/dist/scaffold/private-files.d.ts +2 -0
  124. package/dist/scaffold/private-files.js +78 -0
  125. package/dist/scaffold/stack-documentation.d.ts +0 -1
  126. package/dist/scaffold/stack-documentation.js +3 -49
  127. package/dist/scaffold/styling.d.ts +1 -1
  128. package/dist/scaffold/styling.js +20 -28
  129. package/dist/scaffold/web-billing.d.ts +2 -0
  130. package/dist/scaffold/web-billing.js +48 -0
  131. package/dist/scaffold/workspace.js +53 -189
  132. package/dist/service-deletion.js +1 -1
  133. package/dist/service-descriptor.js +5 -12
  134. package/dist/service-model.d.ts +1 -1
  135. package/dist/service-operations.js +2 -32
  136. package/dist/service-readers.js +1 -32
  137. package/dist/services-command.d.ts +1 -1
  138. package/dist/services-command.js +3 -9
  139. package/dist/ship.d.ts +3 -316
  140. package/dist/ship.js +13 -143
  141. package/dist/stack-registry.d.ts +2 -43
  142. package/dist/stack-registry.js +80 -308
  143. package/dist/standard.js +7 -14
  144. package/dist/version.d.ts +1 -1
  145. package/dist/version.js +1 -1
  146. package/docs/anhedral-stack.md +23 -0
  147. package/docs/assets/anhedral-stack-light.png +0 -0
  148. package/docs/assets/anhedral-stack.png +0 -0
  149. package/docs/software-factory.md +25 -499
  150. package/docs/stack-standard.md +48 -226
  151. package/docs/verification.md +433 -0
  152. package/package.json +22 -21
  153. package/dist/neon-service-data.d.ts +0 -8
  154. package/dist/neon-service-data.js +0 -117
  155. package/dist/platforms/desktop.d.ts +0 -2
  156. package/dist/platforms/desktop.js +0 -415
  157. package/dist/platforms/extension.d.ts +0 -2
  158. package/dist/platforms/extension.js +0 -328
  159. package/dist/scaffold/lint.d.ts +0 -4
  160. package/dist/scaffold/lint.js +0 -56
  161. package/dist/scaffold/neon-realtime.d.ts +0 -2
  162. package/dist/scaffold/neon-realtime.js +0 -97
  163. package/dist/scaffold/services.d.ts +0 -5
  164. package/dist/scaffold/services.js +0 -108
  165. package/dist/scaffold/stream.d.ts +0 -2
  166. package/dist/scaffold/stream.js +0 -114
  167. package/dist/scaffold/void.d.ts +0 -4
  168. package/dist/scaffold/void.js +0 -256
  169. package/dist/scaffold/web.d.ts +0 -2
  170. package/dist/scaffold/web.js +0 -128
  171. package/dist/vercel-project.d.ts +0 -101
  172. package/dist/vercel-project.js +0 -305
  173. package/dist/vercel.d.ts +0 -67
  174. package/dist/vercel.js +0 -581
  175. package/dist/vinext.d.ts +0 -2
  176. package/dist/vinext.js +0 -86
  177. package/dist/void-execution.d.ts +0 -10
  178. package/dist/void-execution.js +0 -94
  179. package/dist/void-migrations.d.ts +0 -6
  180. package/dist/void-migrations.js +0 -110
  181. package/dist/void-state.d.ts +0 -16
  182. package/dist/void-state.js +0 -65
  183. package/dist/void.d.ts +0 -3
  184. package/dist/void.js +0 -5
@@ -3,78 +3,9 @@ import path from 'node:path';
3
3
  import { writeReactLintConfig } from './lint.js';
4
4
  import { appendGitignore, writeFile } from '../util.js';
5
5
  import { childPackageName, jsString } from '../render.js';
6
- import { MOBILE_APP_DEPENDENCIES, MOBILE_NATIVEWIND_DEPENDENCIES, EAS_CLI_VERSION, } from '../dependencies.js';
7
- function writeReactNativeReusablesConfig(dir) {
8
- writeFile(path.join(dir, 'components.json'), JSON.stringify({
9
- $schema: 'https://ui.shadcn.com/schema.json',
10
- style: 'new-york',
11
- rsc: false,
12
- tsx: true,
13
- tailwind: {
14
- config: 'tailwind.config.js',
15
- css: 'global.css',
16
- baseColor: 'neutral',
17
- cssVariables: true,
18
- },
19
- aliases: {
20
- components: '@/components',
21
- utils: '@/lib/utils',
22
- ui: '@/components/ui',
23
- lib: '@/lib',
24
- hooks: '@/hooks',
25
- },
26
- iconLibrary: 'lucide',
27
- }, null, 2) + '\n');
28
- writeFile(path.join(dir, 'lib/utils.ts'), `import { clsx, type ClassValue } from 'clsx';
29
- import { twMerge } from 'tailwind-merge';
30
-
31
- export function cn(...inputs: ClassValue[]) {
32
- return twMerge(clsx(inputs));
33
- }
34
- `);
35
- writeFile(path.join(dir, 'components/ui/button.tsx'), `import { Pressable, Text, type PressableProps } from 'react-native';
36
- import { cn } from '@/lib/utils';
37
-
38
- type ButtonProps = Omit<PressableProps, 'children'> & { children: string; className?: string };
39
-
40
- export function Button({ children, className, ...props }: ButtonProps) {
41
- return <Pressable accessibilityRole="button" className={cn('h-10 items-center justify-center rounded-md bg-primary px-4', className)} {...props}>
42
- <Text className="font-medium text-primary-foreground">{children}</Text>
43
- </Pressable>;
44
- }
45
- `);
46
- writeFile(path.join(dir, 'babel.config.js'), `module.exports = function (api) {
47
- api.cache(true);
48
- return {
49
- presets: [['babel-preset-expo', { jsxImportSource: 'nativewind' }], 'nativewind/babel'],
50
- };
51
- };
52
- `);
53
- writeFile(path.join(dir, 'metro.config.js'), `const { getDefaultConfig } = require('expo/metro-config');
54
- const { withNativeWind } = require('nativewind/metro');
55
-
56
- const config = getDefaultConfig(__dirname);
57
-
58
- module.exports = withNativeWind(config, { input: './global.css', inlineRem: 16 });
59
- `);
60
- writeFile(path.join(dir, 'nativewind-env.d.ts'), '/// <reference types="nativewind/types" />\n');
61
- writeFile(path.join(dir, 'styles.d.ts'), "declare module '*.css';\n");
62
- writeFile(path.join(dir, 'tailwind.config.js'), `const { hairlineWidth } = require('nativewind/theme');
63
-
64
- /** @type {import('tailwindcss').Config} */
65
- module.exports = {
66
- content: ['./app/**/*.{ts,tsx}', './components/**/*.{ts,tsx}'],
67
- presets: [require('nativewind/preset'), require('@workspace/styling/tailwind')],
68
- theme: { extend: { borderWidth: { hairline: hairlineWidth() } } },
69
- future: { hoverOnlyWhenSupported: true },
70
- plugins: [require('tailwindcss-animate')],
71
- };
72
- `);
73
- writeFile(path.join(dir, 'global.css'), `@tailwind base;
74
- @tailwind components;
75
- @tailwind utilities;
76
- `);
77
- }
6
+ import { MOBILE_APP_DEPENDENCIES, EAS_CLI_VERSION } from '../dependencies.js';
7
+ import { scaffoldNativeUI } from '../scaffold/native-ui.js';
8
+ import { scaffoldExpoRuntime } from '../scaffold/expo-runtime.js';
78
9
  function expoScheme(projectName) {
79
10
  const unscoped = projectName.replace(/^@[^/]+\//, '');
80
11
  const safe = unscoped.toLowerCase().replace(/[^a-z0-9+.-]+/g, '-');
@@ -88,36 +19,36 @@ function expoScheme(projectName) {
88
19
  const candidate = normalized || 'app';
89
20
  return /^[a-z]/.test(candidate) ? candidate : `app-${candidate}`;
90
21
  }
91
- export async function scaffoldExpo({ root, options }) {
22
+ export async function scaffoldExpo(context) {
23
+ const { root, options } = context;
92
24
  const dir = path.join(root, 'apps/mobile');
93
25
  const projectName = options.name;
94
26
  const displayName = options.name;
95
27
  const nameLiteral = jsString(displayName);
96
28
  writeReactLintConfig(dir);
29
+ writeFile(path.join(dir, 'babel.config.js'), "module.exports = function(api) { api.cache(true); return { presets: ['babel-preset-expo'] }; };\n");
97
30
  writeFile(path.join(dir, 'package.json'), JSON.stringify({
98
31
  name: childPackageName(projectName, 'mobile'),
99
32
  version: '0.1.0',
100
33
  private: true,
101
34
  main: 'expo-router/entry',
102
35
  scripts: {
103
- dev: 'expo start -c',
104
36
  android: 'expo start -c --android',
105
37
  ios: 'expo start -c --ios',
106
- web: 'expo start -c --web',
107
- build: 'pnpm typecheck && pnpm build:web',
108
- 'build:web': 'expo export --platform web',
38
+ start: 'expo start -c',
39
+ build: 'pnpm typecheck',
40
+ typecheck: 'tsc --noEmit',
41
+ lint: 'eslint . --max-warnings 0',
109
42
  'eas:login': `pnpm dlx eas-cli@${EAS_CLI_VERSION} login`,
110
43
  'build:simulator:ios': `pnpm dlx eas-cli@${EAS_CLI_VERSION} build --platform ios --profile simulator`,
111
44
  'build:internal:ios': `pnpm dlx eas-cli@${EAS_CLI_VERSION} build --platform ios --profile preview`,
112
45
  'build:internal:android': `pnpm dlx eas-cli@${EAS_CLI_VERSION} build --platform android --profile preview`,
113
46
  'build:production:ios': `pnpm dlx eas-cli@${EAS_CLI_VERSION} build --platform ios --profile production`,
114
47
  'build:production:android': `pnpm dlx eas-cli@${EAS_CLI_VERSION} build --platform android --profile production`,
115
- typecheck: 'tsc --noEmit',
116
- lint: 'eslint app components lib --max-warnings 0',
117
48
  },
118
49
  dependencies: {
119
50
  ...MOBILE_APP_DEPENDENCIES.dependencies,
120
- ...MOBILE_NATIVEWIND_DEPENDENCIES.dependencies,
51
+ '@workspace/native-ui': 'workspace:*',
121
52
  '@workspace/styling': 'workspace:*',
122
53
  },
123
54
  devDependencies: {
@@ -132,8 +63,9 @@ export async function scaffoldExpo({ root, options }) {
132
63
  slug: projectName.replace(/^@[^/]+\//, ''),
133
64
  version: '1.0.0',
134
65
  orientation: 'portrait',
66
+ userInterfaceStyle: 'automatic',
135
67
  scheme: expoScheme(projectName),
136
- web: { bundler: 'metro', output: 'static' },
68
+ platforms: ['ios', 'android'],
137
69
  plugins: ['expo-router', 'expo-status-bar'],
138
70
  experiments: { reactCompiler: true, typedRoutes: true },
139
71
  },
@@ -145,48 +77,56 @@ export async function scaffoldExpo({ root, options }) {
145
77
  noUncheckedIndexedAccess: true,
146
78
  paths: { '@/*': ['./*'] },
147
79
  },
148
- include: [
149
- '**/*.ts',
150
- '**/*.tsx',
151
- '.expo/types/**/*.ts',
152
- 'expo-env.d.ts',
153
- 'nativewind-env.d.ts',
154
- ],
80
+ include: ['**/*.ts', '**/*.tsx', '.expo/types/**/*.ts', 'expo-env.d.ts'],
81
+ exclude: ['node_modules', 'worker', '.output', 'worker-configuration.d.ts'],
155
82
  }, null, 2) + '\n');
156
- writeReactNativeReusablesConfig(dir);
157
- writeFile(path.join(dir, 'app/_layout.tsx'), `import '@/global.css';
158
-
159
- import { PortalHost } from '@rn-primitives/portal';
83
+ scaffoldNativeUI(root);
84
+ writeFile(path.join(dir, 'components/ui/button.tsx'), "export { Button } from '@workspace/native-ui';\n");
85
+ writeFile(path.join(dir, 'app/_layout.tsx'), `import '@/lib/development-client';
86
+ import { ThemeProvider } from '@workspace/native-ui';
87
+ import { SafeAreaProvider } from 'react-native-safe-area-context';
160
88
  import { Stack } from 'expo-router';
161
89
 
162
90
  export default function RootLayout() {
163
- return <><Stack /><PortalHost /></>;
91
+ return <SafeAreaProvider><ThemeProvider><Stack /></ThemeProvider></SafeAreaProvider>;
164
92
  }
165
93
  `);
166
- writeFile(path.join(dir, 'app/index.tsx'), `import { StatusBar } from 'expo-status-bar';
167
- import { Linking, ScrollView, StyleSheet, Text, View } from 'react-native';
94
+ writeFile(path.join(dir, 'lib/development-client.ts'), 'export {};\n');
95
+ writeFile(path.join(dir, 'lib/development-client.native.ts'), "import 'expo-dev-client';\n");
96
+ writeFile(path.join(dir, 'app/index.tsx'), `import { useEffect, useState } from 'react';
97
+ import { api } from '@/lib/api-client';
98
+ import { StatusBar } from 'expo-status-bar';
99
+ import { Linking } from 'react-native';
100
+ import { Screen, Stack, Text } from '@workspace/native-ui';
168
101
  import { Button } from '@/components/ui/button';
169
102
 
170
103
  export default function HomeScreen() {
171
- return (
172
- <ScrollView style={styles.screen} contentInsetAdjustmentBehavior="automatic" contentContainerStyle={styles.container}>
173
- <StatusBar style="auto" />
174
- <View style={styles.content}>
175
- <Text accessibilityRole="header" style={styles.title}>{${nameLiteral}}</Text>
176
- <Text selectable style={styles.subtitle}>Expo application scaffold generated by Anhedral.</Text>
177
- <Button onPress={() => void Linking.openURL('https://docs.expo.dev')}>Learn more</Button>
178
- </View>
179
- </ScrollView>
180
- );
181
- }
104
+ const [connection, setConnection] = useState('Connecting to the API…');
105
+ const [pending, setPending] = useState(true);
106
+ useEffect(() => {
107
+ let active = true;
108
+ void api.health().then(
109
+ () => { if (active) setConnection('API connected'); },
110
+ () => { if (active) setConnection('Unable to reach the API. Check the server and device API origin.'); },
111
+ ).finally(() => { if (active) setPending(false); });
112
+ return () => { active = false; };
113
+ }, []);
114
+ async function checkConnection() {
115
+ setPending(true);
116
+ setConnection('Connecting to the API…');
117
+ try { await api.health(); setConnection('API connected'); }
118
+ catch { setConnection('Unable to reach the API. Check the server and device API origin.'); }
119
+ finally { setPending(false); }
120
+ }
182
121
 
183
- const styles = StyleSheet.create({
184
- screen: { flex: 1, backgroundColor: '#f8fafc' },
185
- container: { flexGrow: 1, justifyContent: 'center', padding: 32 },
186
- content: { gap: 12 },
187
- title: { color: '#0f172a', fontSize: 34, fontWeight: '700' },
188
- subtitle: { color: '#475569', fontSize: 17, paddingBottom: 12 },
189
- });
122
+ return <Screen><StatusBar style="auto" /><Stack>
123
+ <Text variant="heading" accessibilityRole="header">{${nameLiteral}}</Text>
124
+ <Text variant="muted">Native iOS and Android application generated by Anhedral.</Text>
125
+ <Text accessibilityLiveRegion="polite">{connection}</Text>
126
+ <Button disabled={pending} onPress={() => void checkConnection()}>{pending ? 'Connecting…' : 'Check API connection'}</Button>
127
+ <Button onPress={() => void Linking.openURL('https://docs.expo.dev')}>Learn more</Button>
128
+ </Stack></Screen>;
129
+ }
190
130
  `);
191
131
  writeFile(path.join(dir, '.env.example'), '');
192
132
  writeFile(path.join(dir, 'eas.json'), JSON.stringify({
@@ -202,5 +142,15 @@ const styles = StyleSheet.create({
202
142
  production: { environment: 'production', autoIncrement: true },
203
143
  },
204
144
  }, null, 2) + '\n');
205
- appendGitignore(dir, ['.env', '.env.*', '!.env.example', '.expo', 'dist', 'node_modules']);
145
+ scaffoldExpoRuntime(context);
146
+ appendGitignore(dir, [
147
+ '.env',
148
+ '.env.*',
149
+ '!.env.example',
150
+ '.expo',
151
+ '.wrangler',
152
+ '.output',
153
+ 'dist',
154
+ 'node_modules',
155
+ ]);
206
156
  }
@@ -0,0 +1,3 @@
1
+ import type { RecipeContext } from '../registry/types.js';
2
+ export declare function scaffoldWeb({ root, options }: RecipeContext): void;
3
+ export declare const WEB_API_PROXY = "export interface ApiBinding { fetch(request: Request): Promise<Response> }\ntype Options = { binding?: ApiBinding; development: boolean; devOrigin?: string; send?: typeof fetch };\nfunction developmentOrigin(configured?: string): string {\n const url = new URL(configured || 'http://127.0.0.1:8787');\n const loopback = new Set(['127.0.0.1', 'localhost', '[::1]']);\n const invalid = [url.protocol !== 'http:', !loopback.has(url.hostname), url.username, url.password, url.pathname !== '/', url.search, url.hash];\n if (invalid.some(Boolean)) throw Error('API_INTERNAL_URL must be a loopback HTTP origin.');\n return url.origin;\n}\nfunction backendOrigin(options: Options): string {\n if (options.development) return developmentOrigin(options.devOrigin);\n if ([!options.binding, options.devOrigin].some(Boolean)) throw Error('Production requires the API service binding.');\n return 'https://api.internal';\n}\nfunction apiTarget(request: Request, origin: string): URL {\n const url = new URL(request.url);\n if (!/^\\/api(?:\\/|$)/.test(url.pathname)) throw Error('Unexpected API path.');\n return new URL(url.pathname + url.search, origin);\n}\nfunction forwardedHeaders(request: Request): Headers {\n const headers = new Headers();\n for (const name of ['accept', 'content-type', 'cookie', 'origin', 'authorization', 'sec-fetch-site', 'expo-origin', 'idempotency-key']) {\n const value = request.headers.get(name); if (value) headers.set(name, value);\n }\n return headers;\n}\nfunction upstreamRequest(request: Request, target: URL): Request {\n const settings: RequestInit & { duplex?: 'half' } = { method: request.method, headers: forwardedHeaders(request), redirect: 'manual', signal: AbortSignal.any([request.signal, AbortSignal.timeout(15000)]) };\n if (!['GET', 'HEAD'].includes(request.method)) { settings.body = request.body; settings.duplex = 'half'; }\n return new Request(target, settings);\n}\nfunction privateResponse(response: Response, development: boolean): Response {\n const headers = new Headers(response.headers);\n for (const name of ['connection', 'transfer-encoding', 'access-control-allow-origin', 'access-control-allow-credentials']) headers.delete(name);\n // Node fetch already decoded the local HTTP response. Next must frame/compress\n // those decoded bytes itself; the sidecar's wire headers no longer describe them.\n if (development) { headers.delete('content-encoding'); headers.delete('content-length'); }\n headers.set('cache-control', 'private, no-store');\n return new Response(response.body, { status: response.status, headers });\n}\nexport async function proxyApi(request: Request, options: Options): Promise<Response> {\n try {\n const upstream = upstreamRequest(request, apiTarget(request, backendOrigin(options)));\n const response = options.development ? await (options.send ?? fetch)(upstream) : await options.binding!.fetch(upstream);\n return privateResponse(response, options.development);\n } catch { return Response.json({ error: 'API unavailable' }, { status: 503, headers: { 'cache-control': 'private, no-store' } }); }\n}\n";
@@ -0,0 +1,299 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { fileURLToPath } from 'node:url';
3
+ import { resourceName, childPackageName, jsString } from '../render.js';
4
+ import { WEB_DEPENDENCIES } from '../dependencies.js';
5
+ import { json, put, workerConfig } from '../scaffold/files.js';
6
+ export function scaffoldWeb({ root, options }) {
7
+ const app = 'apps/web';
8
+ json(root, `${app}/package.json`, {
9
+ name: childPackageName(options.name, 'web'),
10
+ private: true,
11
+ version: '0.1.0',
12
+ type: 'module',
13
+ scripts: {
14
+ dev: 'next dev --turbopack --hostname 0.0.0.0 --port 3000',
15
+ 'build:next': 'next build --webpack',
16
+ build: 'opennextjs-cloudflare build && pnpm build:worker',
17
+ 'build:worker': 'wrangler deploy --dry-run --outdir dist',
18
+ preview: 'wrangler dev --port 3000 --inspector-port 9230',
19
+ deploy: 'wrangler deploy',
20
+ start: 'next start --hostname 0.0.0.0 --port 3000',
21
+ typecheck: 'next typegen && tsc --noEmit',
22
+ lint: 'eslint . --max-warnings 0',
23
+ },
24
+ dependencies: {
25
+ ...WEB_DEPENDENCIES.dependencies,
26
+ '@workspace/contracts': 'workspace:*',
27
+ '@workspace/styling': 'workspace:*',
28
+ },
29
+ devDependencies: {
30
+ ...WEB_DEPENDENCIES.devDependencies,
31
+ '@workspace/eslint-config': 'workspace:*',
32
+ },
33
+ });
34
+ json(root, `${app}/wrangler.jsonc`, {
35
+ ...workerConfig(resourceName(options.name, 'web')),
36
+ main: '.open-next/worker.js',
37
+ compatibility_flags: ['nodejs_compat', 'global_fetch_strictly_public'],
38
+ assets: { directory: '.open-next/assets', binding: 'ASSETS' },
39
+ services: [
40
+ { binding: 'ANHEDRAL_API', service: resourceName(options.name, 'api') },
41
+ { binding: 'WORKER_SELF_REFERENCE', service: resourceName(options.name, 'web') },
42
+ ],
43
+ });
44
+ put(root, `${app}/next.config.ts`, `import type { NextConfig } from 'next';
45
+ const previewOrigin = process.env.NODE_ENV === 'development' ? process.env.ANHEDRAL_PREVIEW_ORIGIN : undefined;
46
+ let allowedDevOrigins: string[] = [];
47
+ if (previewOrigin) {
48
+ const url = new URL(previewOrigin);
49
+ if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.pathname !== '/' || url.search || url.hash) throw new Error('ANHEDRAL_PREVIEW_ORIGIN must be an HTTP(S) origin.');
50
+ allowedDevOrigins = [url.hostname];
51
+ }
52
+ const config: NextConfig = { allowedDevOrigins, transpilePackages: ['@workspace/contracts', '@workspace/styling'], images: { unoptimized: true } };
53
+ export default config;
54
+ `);
55
+ put(root, `${app}/open-next.config.ts`, `import { defineCloudflareConfig } from '@opennextjs/cloudflare';
56
+ const config = { ...defineCloudflareConfig(), buildCommand: 'pnpm build:next' };
57
+ export default config;
58
+ `);
59
+ json(root, `${app}/tsconfig.json`, {
60
+ compilerOptions: {
61
+ target: 'ES2022',
62
+ lib: ['DOM', 'DOM.Iterable', 'ES2022'],
63
+ allowJs: true,
64
+ skipLibCheck: true,
65
+ strict: true,
66
+ noEmit: true,
67
+ esModuleInterop: true,
68
+ module: 'ESNext',
69
+ moduleResolution: 'Bundler',
70
+ resolveJsonModule: true,
71
+ isolatedModules: true,
72
+ jsx: 'react-jsx',
73
+ incremental: true,
74
+ plugins: [{ name: 'next' }],
75
+ paths: { '@/*': ['./*'] },
76
+ },
77
+ include: [
78
+ 'next-env.d.ts',
79
+ '**/*.ts',
80
+ '**/*.tsx',
81
+ '.next/types/**/*.ts',
82
+ '.next/dev/types/**/*.ts',
83
+ ],
84
+ exclude: ['node_modules', '.open-next', 'dist'],
85
+ });
86
+ put(root, `${app}/next-env.d.ts`, '/// <reference types="next" />\n/// <reference types="next/image-types/global" />\n');
87
+ put(root, `${app}/eslint.config.mjs`, `import { defineConfig, globalIgnores } from 'eslint/config';
88
+ import next from 'eslint-config-next/core-web-vitals';
89
+ import ts from 'eslint-config-next/typescript';
90
+ export default defineConfig([...next, ...ts, globalIgnores(['.next/**', '.open-next/**', 'dist/**', 'next-env.d.ts', 'worker-configuration.d.ts'])]);
91
+ `);
92
+ json(root, `${app}/components.json`, {
93
+ $schema: 'https://ui.shadcn.com/schema.json',
94
+ style: 'base-nova',
95
+ rsc: true,
96
+ tsx: true,
97
+ tailwind: { config: '', css: 'app/globals.css', baseColor: 'neutral', cssVariables: true },
98
+ aliases: {
99
+ components: '@/components',
100
+ ui: '@/components/ui',
101
+ utils: '@/lib/utils',
102
+ lib: '@/lib',
103
+ hooks: '@/hooks',
104
+ },
105
+ iconLibrary: 'lucide',
106
+ });
107
+ put(root, `${app}/lib/utils.ts`, `import { clsx, type ClassValue } from 'clsx';
108
+ import { twMerge } from 'tailwind-merge';
109
+ export function cn(...values: ClassValue[]) { return twMerge(clsx(values)); }
110
+ `);
111
+ for (const component of ['button', 'input', 'label'])
112
+ put(root, `${app}/components/ui/${component}.tsx`, readFileSync(fileURLToPath(new URL(`../../assets/ui/web/${component}.tsx`, import.meta.url)), 'utf8'));
113
+ for (const file of ['LICENSE.shadcn', 'UPSTREAM.json'])
114
+ put(root, `${app}/${file}`, readFileSync(fileURLToPath(new URL(`../../assets/ui/${file}`, import.meta.url)), 'utf8'));
115
+ put(root, `${app}/postcss.config.mjs`, "const config = { plugins: { '@tailwindcss/postcss': {} } };\nexport default config;\n");
116
+ put(root, `${app}/app/globals.css`, `@import 'tailwindcss';
117
+ @import '@workspace/styling/globals.css';
118
+ @theme inline {
119
+ --color-background: hsl(var(--background)); --color-foreground: hsl(var(--foreground));
120
+ --color-primary: hsl(var(--primary)); --color-primary-foreground: hsl(var(--primary-foreground));
121
+ --color-secondary: hsl(var(--secondary)); --color-secondary-foreground: hsl(var(--secondary-foreground));
122
+ --color-muted: hsl(var(--muted)); --color-muted-foreground: hsl(var(--muted-foreground));
123
+ --color-border: hsl(var(--border)); --color-input: hsl(var(--input)); --color-ring: hsl(var(--ring));
124
+ --color-destructive: hsl(var(--destructive)); --radius-md: var(--radius); --radius-lg: calc(var(--radius) + 2px);
125
+ }
126
+
127
+ * { box-sizing: border-box; } body { margin: 0; background: hsl(var(--background)); color: hsl(var(--foreground)); font-family: Arial, Helvetica, sans-serif; }
128
+ h1 { font-size: 2rem; font-weight: 600; line-height: 1.2; letter-spacing: -.025em; } h2 { font-size: 1.25rem; font-weight: 600; line-height: 1.4; }
129
+ main { max-width: 64rem; margin: 0 auto; padding: 4rem 1.5rem; } nav, form, .stack { display: flex; gap: 1rem; } form, .stack { flex-direction: column; } form { max-width: 26rem; } label { display: grid; gap: .5rem; }
130
+ a { color: inherit; } .button, input { min-height: 2.75rem; padding: .65rem 1rem; border: 1px solid hsl(var(--border)); border-radius: var(--radius); font: inherit; }
131
+ .button { cursor: pointer; background: hsl(var(--primary)); color: hsl(var(--primary-foreground)); } .button:disabled { opacity: .5; cursor: default; } input { background: hsl(var(--background)); color: inherit; }
132
+ :focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 3px; } .muted { color: hsl(var(--muted-foreground)); }
133
+ `);
134
+ put(root, `${app}/app/layout.tsx`, `import type { Metadata } from 'next';
135
+ import Link from 'next/link';
136
+ import './globals.css';
137
+ export const metadata: Metadata = { title: ${jsString(options.name)}, description: 'Anhedral application' };
138
+ export default function Layout({ children }: { children: React.ReactNode }) { return <html lang="en"><body><main><nav aria-label="Main"><Link href="/">Home</Link><Link href="/account">Account</Link></nav>{children}</main></body></html>; }
139
+ `);
140
+ put(root, `${app}/app/page.tsx`, `import { headers } from 'next/headers';
141
+ export default async function Home() {
142
+ const request = await headers();
143
+ return <section className="stack"><h1>${escapeJsx(options.name)}</h1><p>Next.js on Cloudflare, with a shared Hono API.</p><p className="muted" data-rendering="server">Rendered on the server for {request.get('host') ?? 'this request'}.</p></section>;
144
+ }
145
+ `);
146
+ put(root, `${app}/app/loading.tsx`, `export default function Loading() { return <p role="status">Loading…</p>; }\n`);
147
+ put(root, `${app}/app/error.tsx`, `'use client';\nexport default function ErrorPage({ reset }: { reset: () => void }) { return <section><h1>Unable to load this page</h1><button onClick={reset}>Try again</button></section>; }\n`);
148
+ put(root, `${app}/lib/api-proxy.ts`, WEB_API_PROXY);
149
+ put(root, `${app}/lib/server-api.ts`, `import 'server-only';
150
+ import { getCloudflareContext } from '@opennextjs/cloudflare';
151
+ import { proxyApi, type ApiBinding } from './api-proxy';
152
+ function isApiBinding(value: unknown): value is ApiBinding {
153
+ return typeof value === 'object' && value !== null && typeof Reflect.get(value, 'fetch') === 'function';
154
+ }
155
+ async function productionBinding(): Promise<ApiBinding | undefined> {
156
+ const { env } = await getCloudflareContext({ async: true });
157
+ const candidate: unknown = Reflect.get(env, 'ANHEDRAL_API');
158
+ return isApiBinding(candidate) ? candidate : undefined;
159
+ }
160
+ export async function apiRequest(request: Request): Promise<Response> {
161
+ const development = process.env.NODE_ENV === 'development';
162
+ const binding = development ? undefined : await productionBinding();
163
+ return proxyApi(request, { binding, development, devOrigin: process.env.API_INTERNAL_URL });
164
+ }
165
+ `);
166
+ put(root, `${app}/app/api/[[...path]]/route.ts`, `import { apiRequest } from '@/lib/server-api';
167
+ export const dynamic = 'force-dynamic';
168
+ export const GET = apiRequest;
169
+ export const POST = apiRequest;
170
+ export const PUT = apiRequest;
171
+ export const PATCH = apiRequest;
172
+ export const DELETE = apiRequest;
173
+ export const HEAD = apiRequest;
174
+ export const OPTIONS = apiRequest;
175
+ `);
176
+ put(root, `${app}/lib/auth-client.ts`, `import { createAuthClient } from 'better-auth/react';\nexport const authClient = createAuthClient();\n`);
177
+ put(root, `${app}/app/sign-in/page.tsx`, WEB_SIGN_IN);
178
+ put(root, `${app}/components/sign-out.tsx`, `'use client';
179
+ import { useState } from 'react';
180
+ import { useRouter } from 'next/navigation';
181
+ import { authClient } from '@/lib/auth-client';
182
+ import { Button } from '@/components/ui/button';
183
+ export function SignOut() { const [error, setError] = useState(''); const [pending, setPending] = useState(false); const router = useRouter();
184
+ async function logout() { setPending(true); setError(''); try { const result = await authClient.signOut(); if (result.error) throw Error('Unable to sign out.'); router.replace('/sign-in'); router.refresh(); } catch { setError('Unable to sign out. Please retry.'); } finally { setPending(false); } }
185
+ return <><Button disabled={pending} onClick={() => void logout()}>{pending ? 'Signing out…' : 'Sign out'}</Button><p role="status">{error}</p></>; }
186
+ `);
187
+ put(root, `${app}/app/account/page.tsx`, `import { headers } from 'next/headers';
188
+ import { redirect } from 'next/navigation';
189
+ import { sessionSchema } from '@workspace/contracts';
190
+ import { apiRequest } from '@/lib/server-api';
191
+ import { SignOut } from '@/components/sign-out';
192
+ export default async function Account() {
193
+ const incoming = await headers();
194
+ const response = await apiRequest(new Request('https://app.internal/api/session', { headers: { cookie: incoming.get('cookie') ?? '' } }));
195
+ if (response.status === 401) redirect('/sign-in');
196
+ if (!response.ok) throw Error('Session verification is unavailable.');
197
+ const { user } = sessionSchema.parse(await response.json());
198
+ return <section className="stack"><h1>Account</h1><p>{user.email}</p><SignOut /></section>;
199
+ }
200
+ `);
201
+ put(root, `${app}/.env.example`, '# Development only. Production uses the ANHEDRAL_API service binding.\nAPI_INTERNAL_URL=http://127.0.0.1:8787\n');
202
+ }
203
+ function escapeJsx(value) {
204
+ return value
205
+ .replaceAll('&', '&amp;')
206
+ .replaceAll('<', '&lt;')
207
+ .replaceAll('>', '&gt;')
208
+ .replaceAll('{', '&#123;')
209
+ .replaceAll('}', '&#125;');
210
+ }
211
+ export const WEB_API_PROXY = `export interface ApiBinding { fetch(request: Request): Promise<Response> }
212
+ type Options = { binding?: ApiBinding; development: boolean; devOrigin?: string; send?: typeof fetch };
213
+ function developmentOrigin(configured?: string): string {
214
+ const url = new URL(configured || 'http://127.0.0.1:8787');
215
+ const loopback = new Set(['127.0.0.1', 'localhost', '[::1]']);
216
+ const invalid = [url.protocol !== 'http:', !loopback.has(url.hostname), url.username, url.password, url.pathname !== '/', url.search, url.hash];
217
+ if (invalid.some(Boolean)) throw Error('API_INTERNAL_URL must be a loopback HTTP origin.');
218
+ return url.origin;
219
+ }
220
+ function backendOrigin(options: Options): string {
221
+ if (options.development) return developmentOrigin(options.devOrigin);
222
+ if ([!options.binding, options.devOrigin].some(Boolean)) throw Error('Production requires the API service binding.');
223
+ return 'https://api.internal';
224
+ }
225
+ function apiTarget(request: Request, origin: string): URL {
226
+ const url = new URL(request.url);
227
+ if (!/^\\/api(?:\\/|$)/.test(url.pathname)) throw Error('Unexpected API path.');
228
+ return new URL(url.pathname + url.search, origin);
229
+ }
230
+ function forwardedHeaders(request: Request): Headers {
231
+ const headers = new Headers();
232
+ for (const name of ['accept', 'content-type', 'cookie', 'origin', 'authorization', 'sec-fetch-site', 'expo-origin', 'idempotency-key']) {
233
+ const value = request.headers.get(name); if (value) headers.set(name, value);
234
+ }
235
+ return headers;
236
+ }
237
+ function upstreamRequest(request: Request, target: URL): Request {
238
+ const settings: RequestInit & { duplex?: 'half' } = { method: request.method, headers: forwardedHeaders(request), redirect: 'manual', signal: AbortSignal.any([request.signal, AbortSignal.timeout(15000)]) };
239
+ if (!['GET', 'HEAD'].includes(request.method)) { settings.body = request.body; settings.duplex = 'half'; }
240
+ return new Request(target, settings);
241
+ }
242
+ function privateResponse(response: Response, development: boolean): Response {
243
+ const headers = new Headers(response.headers);
244
+ for (const name of ['connection', 'transfer-encoding', 'access-control-allow-origin', 'access-control-allow-credentials']) headers.delete(name);
245
+ // Node fetch already decoded the local HTTP response. Next must frame/compress
246
+ // those decoded bytes itself; the sidecar's wire headers no longer describe them.
247
+ if (development) { headers.delete('content-encoding'); headers.delete('content-length'); }
248
+ headers.set('cache-control', 'private, no-store');
249
+ return new Response(response.body, { status: response.status, headers });
250
+ }
251
+ export async function proxyApi(request: Request, options: Options): Promise<Response> {
252
+ try {
253
+ const upstream = upstreamRequest(request, apiTarget(request, backendOrigin(options)));
254
+ const response = options.development ? await (options.send ?? fetch)(upstream) : await options.binding!.fetch(upstream);
255
+ return privateResponse(response, options.development);
256
+ } catch { return Response.json({ error: 'API unavailable' }, { status: 503, headers: { 'cache-control': 'private, no-store' } }); }
257
+ }
258
+ `;
259
+ const WEB_SIGN_IN = `'use client';
260
+ import { useRef, useState, type FormEvent } from 'react';
261
+ import { useRouter } from 'next/navigation';
262
+ import Link from 'next/link';
263
+ import { authClient } from '@/lib/auth-client';
264
+ import { Button } from '@/components/ui/button';
265
+ import { Input } from '@/components/ui/input';
266
+ import { Label } from '@/components/ui/label';
267
+ function verificationPending(create: boolean, signedIn: boolean): boolean { return create && !signedIn; }
268
+ async function requestVerification(email: string) {
269
+ const result = await authClient.sendVerificationEmail({ email, callbackURL: '/sign-in' });
270
+ if (result.error) throw Error('Verification unavailable');
271
+ }
272
+ async function authenticate(data: FormData, create: boolean) {
273
+ const email = String(data.get('email')); const password = String(data.get('password')); const name = String(data.get('name'));
274
+ const result = create ? await authClient.signUp.email({ email, password, name, callbackURL: '/sign-in' }) : await authClient.signIn.email({ email, password });
275
+ if (result.error) throw Error('Sign in failed.');
276
+ return Boolean(result.data?.token);
277
+ }
278
+ export default function SignIn() {
279
+ const form = useRef<HTMLFormElement>(null);
280
+ const router = useRouter(); const [create, setCreate] = useState(false); const [pending, setPending] = useState(false); const [error, setError] = useState('');
281
+ async function submit(event: FormEvent<HTMLFormElement>) { event.preventDefault(); if (pending) return; setPending(true); setError('');
282
+ const data = new FormData(event.currentTarget);
283
+ try { const signedIn = await authenticate(data, create); if (verificationPending(create, signedIn)) { form.current?.reset(); setCreate(false); setError('Check your email to verify your account, then sign in.'); return; } router.replace('/account'); router.refresh(); } catch { setError('Unable to sign in. Check your details and retry.'); } finally { setPending(false); }
284
+ }
285
+ async function resend() {
286
+ const input = form.current?.querySelector<HTMLInputElement>('[name="email"]');
287
+ if (pending || !input?.reportValidity()) return;
288
+ const email = input.value;
289
+ setPending(true); setError('');
290
+ try {
291
+ await requestVerification(email);
292
+ setError('If verification is needed, check your email for the link.');
293
+ } catch { setError('Unable to request verification. Please retry.'); }
294
+ finally { setPending(false); }
295
+ }
296
+ const labels = create ? { title: 'Create account', password: 'new-password', toggle: 'Use an existing account' } : { title: 'Sign in', password: 'current-password', toggle: 'Create an account' };
297
+ return <section className="stack"><h1>{labels.title}</h1><form ref={form} onSubmit={submit}>{create && <Label>Name<Input name="name" required autoComplete="name" /></Label>}<Label>Email<Input name="email" type="email" required autoComplete="email" /></Label><Label>Password<Input name="password" type="password" minLength={8} required autoComplete={labels.password} /></Label><Button type="submit" disabled={pending}>{pending ? 'Working…' : labels.title}</Button><p role="status">{error}</p><Link href="/reset-password">Forgot your password?</Link><Button type="button" disabled={pending} onClick={() => void resend()}>Resend verification email</Button><Button type="button" disabled={pending} onClick={() => setCreate(!create)}>{labels.toggle}</Button></form></section>;
298
+ }
299
+ `;
@@ -1,6 +1,6 @@
1
1
  export declare const PROJECT_CONFIG_FILE = "anhedral.json";
2
2
  export declare const PROJECT_CONFIG_MAX_BYTES: number;
3
- export declare const PROJECT_CONFIG_SECTIONS: readonly ["identity", "standard", "setup", "providers", "cloudflare", "vercel", "registry"];
3
+ export declare const PROJECT_CONFIG_SECTIONS: readonly ["identity", "standard", "setup", "providers", "cloudflare", "registry"];
4
4
  export type ProjectSection = (typeof PROJECT_CONFIG_SECTIONS)[number];
5
5
  export type ProjectConfig = {
6
6
  schemaVersion: 1;
@@ -11,7 +11,6 @@ export const PROJECT_CONFIG_SECTIONS = [
11
11
  'setup',
12
12
  'providers',
13
13
  'cloudflare',
14
- 'vercel',
15
14
  'registry',
16
15
  ];
17
16
  /** Validate the envelope independently; each domain validates its own selected section. */