anhedral 0.13.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.
Files changed (360) hide show
  1. package/README.md +23 -229
  2. package/assets/patches/audit-deps.mjs +12 -2
  3. package/assets/stack/ai-schema.ts.txt +5 -0
  4. package/assets/stack/ai.ts.txt +30 -0
  5. package/assets/stack/api-index.ts.txt +15 -0
  6. package/assets/stack/auth-features.ts.txt +4 -0
  7. package/assets/stack/auth-journal.json.txt +13 -0
  8. package/assets/stack/auth-migration.sql.txt +53 -0
  9. package/assets/stack/auth-routes.ts.txt +11 -0
  10. package/assets/stack/auth-schema.ts.txt +64 -0
  11. package/assets/stack/auth-snapshot.json.txt +346 -0
  12. package/assets/stack/auth.ts.txt +32 -0
  13. package/assets/stack/billing-mode.ts.txt +8 -0
  14. package/assets/stack/billing-schema.ts.txt +11 -0
  15. package/assets/stack/desktop.rs.txt +21 -0
  16. package/assets/stack/entitlement-guard.ts.txt +32 -0
  17. package/assets/stack/entitlements.ts.txt +8 -0
  18. package/assets/stack/events-schema.ts.txt +12 -0
  19. package/assets/stack/events.ts.txt +59 -0
  20. package/assets/stack/mobile-auth.ts.txt +25 -0
  21. package/assets/stack/mobile-billing.tsx.txt +63 -0
  22. package/assets/stack/mobile-session.tsx.txt +83 -0
  23. package/assets/stack/native-button.tsx.txt +108 -0
  24. package/assets/stack/native-global.css.txt +4 -0
  25. package/assets/stack/native-lib-utils.ts.txt +5 -0
  26. package/assets/stack/native-metro.config.js.txt +6 -0
  27. package/assets/stack/native-nativewind-env.d.ts.txt +1 -0
  28. package/assets/stack/native-tailwind.config.js.txt +73 -0
  29. package/assets/stack/native-text.tsx.txt +89 -0
  30. package/assets/stack/purchases.ts.txt +65 -0
  31. package/assets/stack/revenuecat.ts.txt +88 -0
  32. package/assets/stack/rtc-schema.ts.txt +10 -0
  33. package/assets/stack/rtc.ts.txt +122 -0
  34. package/assets/stack/security.ts.txt +31 -0
  35. package/assets/stack/storage.ts.txt +36 -0
  36. package/assets/stack/stripe.ts.txt +126 -0
  37. package/assets/stack/web-sign-in.tsx.txt +51 -0
  38. package/assets/ui/LICENSE.react-native-reusables +21 -0
  39. package/assets/ui/LICENSE.shadcn +21 -0
  40. package/assets/ui/UPSTREAM.json +39 -0
  41. package/assets/ui/catalog.json +891 -0
  42. package/assets/ui/extensions/registry.json +6 -0
  43. package/assets/ui/native/_controls.tsx +521 -0
  44. package/assets/ui/native/_core.tsx +118 -0
  45. package/assets/ui/native/_data.tsx +200 -0
  46. package/assets/ui/native/_display.tsx +453 -0
  47. package/assets/ui/native/_feedback.tsx +242 -0
  48. package/assets/ui/native/_legacy-dialog.tsx +38 -0
  49. package/assets/ui/native/_motion.tsx +520 -0
  50. package/assets/ui/native/_overlay.tsx +402 -0
  51. package/assets/ui/native/_selection.tsx +366 -0
  52. package/assets/ui/native/accordion.tsx +1 -0
  53. package/assets/ui/native/alert-dialog.tsx +11 -0
  54. package/assets/ui/native/alert.tsx +1 -0
  55. package/assets/ui/native/aspect-ratio.tsx +1 -0
  56. package/assets/ui/native/attachment.tsx +8 -0
  57. package/assets/ui/native/avatar.tsx +8 -0
  58. package/assets/ui/native/badge.tsx +1 -0
  59. package/assets/ui/native/breadcrumb.tsx +9 -0
  60. package/assets/ui/native/bubble.tsx +1 -0
  61. package/assets/ui/native/button-group.tsx +1 -0
  62. package/assets/ui/native/button.tsx +86 -0
  63. package/assets/ui/native/calendar.tsx +170 -0
  64. package/assets/ui/native/card.tsx +44 -0
  65. package/assets/ui/native/carousel.tsx +1 -0
  66. package/assets/ui/native/chart.tsx +193 -0
  67. package/assets/ui/native/checkbox.tsx +1 -0
  68. package/assets/ui/native/code-block.tsx +137 -0
  69. package/assets/ui/native/collapsible.tsx +1 -0
  70. package/assets/ui/native/combobox.tsx +1 -0
  71. package/assets/ui/native/command.tsx +11 -0
  72. package/assets/ui/native/context-menu.tsx +16 -0
  73. package/assets/ui/native/data-table.tsx +1 -0
  74. package/assets/ui/native/date-picker.tsx +43 -0
  75. package/assets/ui/native/dialog.tsx +15 -0
  76. package/assets/ui/native/direction.tsx +1 -0
  77. package/assets/ui/native/drawer.tsx +10 -0
  78. package/assets/ui/native/dropdown-menu.tsx +16 -0
  79. package/assets/ui/native/empty.tsx +8 -0
  80. package/assets/ui/native/field.tsx +13 -0
  81. package/assets/ui/native/hover-card.tsx +1 -0
  82. package/assets/ui/native/input-group.tsx +8 -0
  83. package/assets/ui/native/input-otp.tsx +1 -0
  84. package/assets/ui/native/input.tsx +28 -0
  85. package/assets/ui/native/item.tsx +12 -0
  86. package/assets/ui/native/kbd.tsx +1 -0
  87. package/assets/ui/native/label.tsx +4 -0
  88. package/assets/ui/native/layout.tsx +26 -0
  89. package/assets/ui/native/marker.tsx +1 -0
  90. package/assets/ui/native/menubar.tsx +17 -0
  91. package/assets/ui/native/message-scroller.tsx +6 -0
  92. package/assets/ui/native/message.tsx +10 -0
  93. package/assets/ui/native/native-select.tsx +1 -0
  94. package/assets/ui/native/navigation-menu.tsx +10 -0
  95. package/assets/ui/native/pagination.tsx +9 -0
  96. package/assets/ui/native/popover.tsx +1 -0
  97. package/assets/ui/native/progress.tsx +1 -0
  98. package/assets/ui/native/questionnaire.tsx +130 -0
  99. package/assets/ui/native/radio-group.tsx +1 -0
  100. package/assets/ui/native/registry.json +1103 -0
  101. package/assets/ui/native/resizable.tsx +1 -0
  102. package/assets/ui/native/scroll-area.tsx +1 -0
  103. package/assets/ui/native/select.tsx +11 -0
  104. package/assets/ui/native/separator.tsx +1 -0
  105. package/assets/ui/native/sheet.tsx +10 -0
  106. package/assets/ui/native/sidebar.tsx +22 -0
  107. package/assets/ui/native/skeleton.tsx +1 -0
  108. package/assets/ui/native/slider.tsx +1 -0
  109. package/assets/ui/native/spinner.tsx +1 -0
  110. package/assets/ui/native/switch.tsx +1 -0
  111. package/assets/ui/native/table.tsx +10 -0
  112. package/assets/ui/native/tabs.tsx +1 -0
  113. package/assets/ui/native/text.tsx +20 -0
  114. package/assets/ui/native/textarea.tsx +1 -0
  115. package/assets/ui/native/theme-switcher.tsx +22 -0
  116. package/assets/ui/native/toast.tsx +11 -0
  117. package/assets/ui/native/toggle-group.tsx +1 -0
  118. package/assets/ui/native/toggle.tsx +1 -0
  119. package/assets/ui/native/tooltip.tsx +1 -0
  120. package/assets/ui/native/trace.tsx +20 -0
  121. package/assets/ui/native/typography.tsx +15 -0
  122. package/assets/ui/theme-storage.ts +25 -0
  123. package/assets/ui/theme.tsx +66 -0
  124. package/assets/ui/web/button.tsx +59 -0
  125. package/assets/ui/web/input.tsx +21 -0
  126. package/assets/ui/web/label.tsx +19 -0
  127. package/dist/bin.js +7 -12
  128. package/dist/capabilities.d.ts +4 -33
  129. package/dist/capabilities.js +2 -84
  130. package/dist/capability-catalog.d.ts +83 -0
  131. package/dist/capability-catalog.js +121 -0
  132. package/dist/capability-command.d.ts +3 -0
  133. package/dist/capability-command.js +188 -0
  134. package/dist/capability-editor.d.ts +17 -0
  135. package/dist/capability-editor.js +97 -0
  136. package/dist/capability-recipes.d.ts +4 -0
  137. package/dist/capability-recipes.js +520 -0
  138. package/dist/capability-references.d.ts +4 -0
  139. package/dist/capability-references.js +7 -0
  140. package/dist/cli-commands.d.ts +1 -2
  141. package/dist/cli-commands.js +10 -104
  142. package/dist/cli-output.d.ts +1 -2
  143. package/dist/cli-output.js +6 -251
  144. package/dist/command-schema.js +40 -374
  145. package/dist/dependencies.d.ts +34 -62
  146. package/dist/dependencies.js +112 -199
  147. package/dist/index.d.ts +1 -45
  148. package/dist/index.js +1 -30
  149. package/dist/platforms/mobile.js +29 -139
  150. package/dist/platforms/web.d.ts +3 -0
  151. package/dist/platforms/web.js +251 -0
  152. package/dist/project-config.d.ts +2 -13
  153. package/dist/project-config.js +10 -83
  154. package/dist/registry/context.js +0 -1
  155. package/dist/registry/options.js +6 -40
  156. package/dist/registry/resolve.d.ts +3 -4
  157. package/dist/registry/resolve.js +18 -108
  158. package/dist/registry/types.d.ts +1 -7
  159. package/dist/registry/usage.js +3 -9
  160. package/dist/runtime-policy.d.ts +0 -2
  161. package/dist/runtime-policy.js +0 -16
  162. package/dist/scaffold/backend.d.ts +0 -4
  163. package/dist/scaffold/backend.js +1 -189
  164. package/dist/scaffold/bootstrap.d.ts +2 -3
  165. package/dist/scaffold/bootstrap.js +37 -43
  166. package/dist/scaffold/compose.js +2 -14
  167. package/dist/scaffold/database.d.ts +1 -1
  168. package/dist/scaffold/database.js +19 -126
  169. package/dist/scaffold/documentation.d.ts +0 -1
  170. package/dist/scaffold/documentation.js +82 -84
  171. package/dist/scaffold/expo-runtime.d.ts +2 -2
  172. package/dist/scaffold/expo-runtime.js +9 -101
  173. package/dist/scaffold/native-ui.d.ts +2 -0
  174. package/dist/scaffold/native-ui.js +74 -0
  175. package/dist/scaffold/stack-documentation.d.ts +0 -1
  176. package/dist/scaffold/stack-documentation.js +3 -49
  177. package/dist/scaffold/storage.d.ts +2 -0
  178. package/dist/scaffold/storage.js +21 -0
  179. package/dist/scaffold/styling.d.ts +1 -1
  180. package/dist/scaffold/styling.js +20 -28
  181. package/dist/scaffold/workspace.js +63 -199
  182. package/dist/stack-registry.d.ts +2 -58
  183. package/dist/stack-registry.js +22 -446
  184. package/dist/standard.js +7 -24
  185. package/dist/ui-catalog.d.ts +26 -0
  186. package/dist/ui-catalog.js +31 -0
  187. package/dist/ui-command.d.ts +3 -0
  188. package/dist/ui-command.js +219 -0
  189. package/dist/ui-project.d.ts +22 -0
  190. package/dist/ui-project.js +110 -0
  191. package/dist/version.d.ts +1 -1
  192. package/dist/version.js +1 -1
  193. package/docs/anhedral-stack.md +4 -119
  194. package/docs/capabilities.md +110 -0
  195. package/docs/native-ui.md +102 -0
  196. package/docs/software-factory.md +16 -577
  197. package/docs/stack-standard.md +11 -307
  198. package/docs/ui.md +33 -0
  199. package/docs/verification.md +511 -0
  200. package/package.json +26 -27
  201. package/dist/access.d.ts +0 -10
  202. package/dist/access.js +0 -93
  203. package/dist/auth-schema-snapshot.d.ts +0 -346
  204. package/dist/auth-schema-snapshot.js +0 -347
  205. package/dist/auth-schema.d.ts +0 -1
  206. package/dist/auth-schema.js +0 -57
  207. package/dist/capability-contract.d.ts +0 -47
  208. package/dist/capability-contract.js +0 -168
  209. package/dist/catalog-model.d.ts +0 -24
  210. package/dist/catalog-model.js +0 -1
  211. package/dist/catalog-registration.d.ts +0 -16
  212. package/dist/catalog-registration.js +0 -22
  213. package/dist/catalog-snapshot.d.ts +0 -5
  214. package/dist/catalog-snapshot.js +0 -97
  215. package/dist/cli-delivery.d.ts +0 -3
  216. package/dist/cli-delivery.js +0 -172
  217. package/dist/cloudflare.d.ts +0 -25
  218. package/dist/cloudflare.js +0 -226
  219. package/dist/delivery-evidence.d.ts +0 -62
  220. package/dist/delivery-evidence.js +0 -186
  221. package/dist/delivery.d.ts +0 -88
  222. package/dist/delivery.js +0 -570
  223. package/dist/inspector-model.d.ts +0 -123
  224. package/dist/inspector-model.js +0 -1
  225. package/dist/integration-service-readers.d.ts +0 -13
  226. package/dist/integration-service-readers.js +0 -173
  227. package/dist/lifecycle-model.d.ts +0 -15
  228. package/dist/lifecycle-model.js +0 -20
  229. package/dist/lifecycle.d.ts +0 -11
  230. package/dist/lifecycle.js +0 -91
  231. package/dist/management.d.ts +0 -3
  232. package/dist/management.js +0 -47
  233. package/dist/mobile-delivery.d.ts +0 -77
  234. package/dist/mobile-delivery.js +0 -366
  235. package/dist/neon-service-data.d.ts +0 -8
  236. package/dist/neon-service-data.js +0 -117
  237. package/dist/platforms/desktop.d.ts +0 -2
  238. package/dist/platforms/desktop.js +0 -415
  239. package/dist/platforms/extension.d.ts +0 -2
  240. package/dist/platforms/extension.js +0 -328
  241. package/dist/project-catalog.d.ts +0 -41
  242. package/dist/project-catalog.js +0 -288
  243. package/dist/project-inspector.d.ts +0 -4
  244. package/dist/project-inspector.js +0 -702
  245. package/dist/project-lifecycle.d.ts +0 -25
  246. package/dist/project-lifecycle.js +0 -57
  247. package/dist/project-state.d.ts +0 -49
  248. package/dist/project-state.js +0 -563
  249. package/dist/provider-auth.d.ts +0 -41
  250. package/dist/provider-auth.js +0 -215
  251. package/dist/provider-readiness.d.ts +0 -30
  252. package/dist/provider-readiness.js +0 -104
  253. package/dist/providers/adapters.d.ts +0 -17
  254. package/dist/providers/adapters.js +0 -278
  255. package/dist/providers/api.d.ts +0 -29
  256. package/dist/providers/api.js +0 -253
  257. package/dist/providers/config.d.ts +0 -15
  258. package/dist/providers/config.js +0 -182
  259. package/dist/providers/definitions.d.ts +0 -318
  260. package/dist/providers/definitions.js +0 -127
  261. package/dist/providers/provision.d.ts +0 -24
  262. package/dist/providers/provision.js +0 -76
  263. package/dist/providers/receipts.d.ts +0 -20
  264. package/dist/providers/receipts.js +0 -66
  265. package/dist/providers/recovery-verification.d.ts +0 -7
  266. package/dist/providers/recovery-verification.js +0 -112
  267. package/dist/providers/recovery.d.ts +0 -30
  268. package/dist/providers/recovery.js +0 -34
  269. package/dist/providers/runtime.d.ts +0 -10
  270. package/dist/providers/runtime.js +0 -265
  271. package/dist/providers/schema.d.ts +0 -28
  272. package/dist/providers/schema.js +0 -49
  273. package/dist/providers/state.d.ts +0 -55
  274. package/dist/providers/state.js +0 -289
  275. package/dist/provision.d.ts +0 -55
  276. package/dist/provision.js +0 -284
  277. package/dist/r2-service-data.d.ts +0 -2
  278. package/dist/r2-service-data.js +0 -136
  279. package/dist/readiness.d.ts +0 -23
  280. package/dist/readiness.js +0 -122
  281. package/dist/registry/add.d.ts +0 -24
  282. package/dist/registry/add.js +0 -270
  283. package/dist/registry/bootstrap.d.ts +0 -2
  284. package/dist/registry/bootstrap.js +0 -14
  285. package/dist/registry/commands.d.ts +0 -3
  286. package/dist/registry/commands.js +0 -85
  287. package/dist/registry/presets.d.ts +0 -4
  288. package/dist/registry/presets.js +0 -41
  289. package/dist/registry/preview.d.ts +0 -11
  290. package/dist/registry/preview.js +0 -91
  291. package/dist/registry/receipt.d.ts +0 -3
  292. package/dist/registry/receipt.js +0 -68
  293. package/dist/repository.d.ts +0 -24
  294. package/dist/repository.js +0 -96
  295. package/dist/scaffold/auth.d.ts +0 -3
  296. package/dist/scaffold/auth.js +0 -151
  297. package/dist/scaffold/billing-config.d.ts +0 -1
  298. package/dist/scaffold/billing-config.js +0 -73
  299. package/dist/scaffold/billing-contracts.d.ts +0 -2
  300. package/dist/scaffold/billing-contracts.js +0 -48
  301. package/dist/scaffold/billing-providers.d.ts +0 -1
  302. package/dist/scaffold/billing-providers.js +0 -249
  303. package/dist/scaffold/billing-schema.d.ts +0 -1
  304. package/dist/scaffold/billing-schema.js +0 -34
  305. package/dist/scaffold/billing-security.d.ts +0 -1
  306. package/dist/scaffold/billing-security.js +0 -46
  307. package/dist/scaffold/billing-server.d.ts +0 -1
  308. package/dist/scaffold/billing-server.js +0 -139
  309. package/dist/scaffold/billing-store.d.ts +0 -1
  310. package/dist/scaffold/billing-store.js +0 -72
  311. package/dist/scaffold/billing.d.ts +0 -2
  312. package/dist/scaffold/billing.js +0 -216
  313. package/dist/scaffold/cloudflare-services.d.ts +0 -8
  314. package/dist/scaffold/cloudflare-services.js +0 -198
  315. package/dist/scaffold/expo-auth.d.ts +0 -3
  316. package/dist/scaffold/expo-auth.js +0 -192
  317. package/dist/scaffold/expo-billing.d.ts +0 -3
  318. package/dist/scaffold/expo-billing.js +0 -292
  319. package/dist/scaffold/integrations.d.ts +0 -4
  320. package/dist/scaffold/integrations.js +0 -12
  321. package/dist/scaffold/lint.d.ts +0 -4
  322. package/dist/scaffold/lint.js +0 -56
  323. package/dist/scaffold/neon-realtime.d.ts +0 -2
  324. package/dist/scaffold/neon-realtime.js +0 -97
  325. package/dist/scaffold/services.d.ts +0 -5
  326. package/dist/scaffold/services.js +0 -108
  327. package/dist/scaffold/stream.d.ts +0 -2
  328. package/dist/scaffold/stream.js +0 -114
  329. package/dist/scaffold/void.d.ts +0 -4
  330. package/dist/scaffold/void.js +0 -264
  331. package/dist/scaffold/web.d.ts +0 -2
  332. package/dist/scaffold/web.js +0 -130
  333. package/dist/service-deletion.d.ts +0 -29
  334. package/dist/service-deletion.js +0 -195
  335. package/dist/service-descriptor.d.ts +0 -10
  336. package/dist/service-descriptor.js +0 -78
  337. package/dist/service-model.d.ts +0 -49
  338. package/dist/service-model.js +0 -8
  339. package/dist/service-operations.d.ts +0 -29
  340. package/dist/service-operations.js +0 -78
  341. package/dist/service-readers.d.ts +0 -8
  342. package/dist/service-readers.js +0 -247
  343. package/dist/services-command.d.ts +0 -39
  344. package/dist/services-command.js +0 -102
  345. package/dist/ship.d.ts +0 -348
  346. package/dist/ship.js +0 -239
  347. package/dist/vercel-project.d.ts +0 -101
  348. package/dist/vercel-project.js +0 -305
  349. package/dist/vercel.d.ts +0 -67
  350. package/dist/vercel.js +0 -581
  351. package/dist/vinext.d.ts +0 -2
  352. package/dist/vinext.js +0 -86
  353. package/dist/void-execution.d.ts +0 -10
  354. package/dist/void-execution.js +0 -94
  355. package/dist/void-migrations.d.ts +0 -6
  356. package/dist/void-migrations.js +0 -110
  357. package/dist/void-state.d.ts +0 -16
  358. package/dist/void-state.js +0 -65
  359. package/dist/void.d.ts +0 -3
  360. package/dist/void.js +0 -5
@@ -3,79 +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';
6
+ import { MOBILE_APP_DEPENDENCIES } from '../dependencies.js';
7
+ import { scaffoldNativeUI } from '../scaffold/native-ui.js';
7
8
  import { scaffoldExpoRuntime } from '../scaffold/expo-runtime.js';
8
- function writeReactNativeReusablesConfig(dir) {
9
- writeFile(path.join(dir, 'components.json'), JSON.stringify({
10
- $schema: 'https://ui.shadcn.com/schema.json',
11
- style: 'new-york',
12
- rsc: false,
13
- tsx: true,
14
- tailwind: {
15
- config: 'tailwind.config.js',
16
- css: 'global.css',
17
- baseColor: 'neutral',
18
- cssVariables: true,
19
- },
20
- aliases: {
21
- components: '@/components',
22
- utils: '@/lib/utils',
23
- ui: '@/components/ui',
24
- lib: '@/lib',
25
- hooks: '@/hooks',
26
- },
27
- iconLibrary: 'lucide',
28
- }, null, 2) + '\n');
29
- writeFile(path.join(dir, 'lib/utils.ts'), `import { clsx, type ClassValue } from 'clsx';
30
- import { twMerge } from 'tailwind-merge';
31
-
32
- export function cn(...inputs: ClassValue[]) {
33
- return twMerge(clsx(inputs));
34
- }
35
- `);
36
- writeFile(path.join(dir, 'components/ui/button.tsx'), `import { Pressable, Text, type PressableProps } from 'react-native';
37
- import { cn } from '@/lib/utils';
38
-
39
- type ButtonProps = Omit<PressableProps, 'children'> & { children: string; className?: string };
40
-
41
- export function Button({ children, className, ...props }: ButtonProps) {
42
- return <Pressable accessibilityRole="button" className={cn('h-10 items-center justify-center rounded-md bg-primary px-4', className)} {...props}>
43
- <Text className="font-medium text-primary-foreground">{children}</Text>
44
- </Pressable>;
45
- }
46
- `);
47
- writeFile(path.join(dir, 'babel.config.js'), `module.exports = function (api) {
48
- api.cache(true);
49
- return {
50
- presets: [['babel-preset-expo', { jsxImportSource: 'nativewind' }], 'nativewind/babel'],
51
- };
52
- };
53
- `);
54
- writeFile(path.join(dir, 'metro.config.js'), `const { getDefaultConfig } = require('expo/metro-config');
55
- const { withNativeWind } = require('nativewind/metro');
56
-
57
- const config = getDefaultConfig(__dirname);
58
-
59
- module.exports = withNativeWind(config, { input: './global.css', inlineRem: 16 });
60
- `);
61
- writeFile(path.join(dir, 'nativewind-env.d.ts'), '/// <reference types="nativewind/types" />\n');
62
- writeFile(path.join(dir, 'styles.d.ts'), "declare module '*.css';\n");
63
- writeFile(path.join(dir, 'tailwind.config.js'), `const { hairlineWidth } = require('nativewind/theme');
64
-
65
- /** @type {import('tailwindcss').Config} */
66
- module.exports = {
67
- content: ['./app/**/*.{ts,tsx}', './components/**/*.{ts,tsx}'],
68
- presets: [require('nativewind/preset'), require('@workspace/styling/tailwind')],
69
- theme: { extend: { borderWidth: { hairline: hairlineWidth() } } },
70
- future: { hoverOnlyWhenSupported: true },
71
- plugins: [require('tailwindcss-animate')],
72
- };
73
- `);
74
- writeFile(path.join(dir, 'global.css'), `@tailwind base;
75
- @tailwind components;
76
- @tailwind utilities;
77
- `);
78
- }
79
9
  function expoScheme(projectName) {
80
10
  const unscoped = projectName.replace(/^@[^/]+\//, '');
81
11
  const safe = unscoped.toLowerCase().replace(/[^a-z0-9+.-]+/g, '-');
@@ -96,30 +26,23 @@ export async function scaffoldExpo(context) {
96
26
  const displayName = options.name;
97
27
  const nameLiteral = jsString(displayName);
98
28
  writeReactLintConfig(dir);
29
+ writeFile(path.join(dir, 'babel.config.js'), "module.exports = function(api) { api.cache(true); return { presets: ['babel-preset-expo'] }; };\n");
99
30
  writeFile(path.join(dir, 'package.json'), JSON.stringify({
100
31
  name: childPackageName(projectName, 'mobile'),
101
32
  version: '0.1.0',
102
33
  private: true,
103
34
  main: 'expo-router/entry',
104
35
  scripts: {
105
- dev: 'expo start -c',
106
36
  android: 'expo start -c --android',
107
37
  ios: 'expo start -c --ios',
108
- web: 'expo start -c --web',
109
- build: 'pnpm typecheck && pnpm build:web',
110
- 'build:web': 'expo export --platform web',
111
- 'eas:login': `pnpm dlx eas-cli@${EAS_CLI_VERSION} login`,
112
- 'build:simulator:ios': `pnpm dlx eas-cli@${EAS_CLI_VERSION} build --platform ios --profile simulator`,
113
- 'build:internal:ios': `pnpm dlx eas-cli@${EAS_CLI_VERSION} build --platform ios --profile preview`,
114
- 'build:internal:android': `pnpm dlx eas-cli@${EAS_CLI_VERSION} build --platform android --profile preview`,
115
- 'build:production:ios': `pnpm dlx eas-cli@${EAS_CLI_VERSION} build --platform ios --profile production`,
116
- 'build:production:android': `pnpm dlx eas-cli@${EAS_CLI_VERSION} build --platform android --profile production`,
38
+ start: 'expo start -c',
39
+ build: 'pnpm typecheck',
117
40
  typecheck: 'tsc --noEmit',
118
- lint: 'eslint app components lib --max-warnings 0',
41
+ lint: 'eslint . --max-warnings 0',
119
42
  },
120
43
  dependencies: {
121
44
  ...MOBILE_APP_DEPENDENCIES.dependencies,
122
- ...MOBILE_NATIVEWIND_DEPENDENCIES.dependencies,
45
+ '@workspace/native-ui': 'workspace:*',
123
46
  '@workspace/styling': 'workspace:*',
124
47
  },
125
48
  devDependencies: {
@@ -136,7 +59,7 @@ export async function scaffoldExpo(context) {
136
59
  orientation: 'portrait',
137
60
  userInterfaceStyle: 'automatic',
138
61
  scheme: expoScheme(projectName),
139
- web: { bundler: 'metro', output: 'static' },
62
+ platforms: ['ios', 'android'],
140
63
  plugins: ['expo-router', 'expo-status-bar'],
141
64
  experiments: { reactCompiler: true, typedRoutes: true },
142
65
  },
@@ -148,35 +71,31 @@ export async function scaffoldExpo(context) {
148
71
  noUncheckedIndexedAccess: true,
149
72
  paths: { '@/*': ['./*'] },
150
73
  },
151
- include: [
152
- '**/*.ts',
153
- '**/*.tsx',
154
- '.expo/types/**/*.ts',
155
- 'expo-env.d.ts',
156
- 'nativewind-env.d.ts',
157
- ],
74
+ include: ['**/*.ts', '**/*.tsx', '.expo/types/**/*.ts', 'expo-env.d.ts'],
158
75
  exclude: ['node_modules', 'worker', '.output', 'worker-configuration.d.ts'],
159
76
  }, null, 2) + '\n');
160
- writeReactNativeReusablesConfig(dir);
161
- writeFile(path.join(dir, 'app/_layout.tsx'), `import '@/global.css';
162
- import '@/lib/development-client';
163
-
164
- import { PortalHost } from '@rn-primitives/portal';
77
+ scaffoldNativeUI(root);
78
+ writeFile(path.join(dir, 'components/ui/button.tsx'), "export { Button } from '@workspace/native-ui';\n");
79
+ writeFile(path.join(dir, 'app/_layout.tsx'), `import '@/lib/development-client';
80
+ import { ThemeProvider } from '@workspace/native-ui';
81
+ import { SafeAreaProvider } from 'react-native-safe-area-context';
165
82
  import { Stack } from 'expo-router';
166
83
 
167
84
  export default function RootLayout() {
168
- return <><Stack /><PortalHost /></>;
85
+ return <SafeAreaProvider><ThemeProvider><Stack /></ThemeProvider></SafeAreaProvider>;
169
86
  }
170
87
  `);
171
88
  writeFile(path.join(dir, 'lib/development-client.ts'), 'export {};\n');
172
89
  writeFile(path.join(dir, 'lib/development-client.native.ts'), "import 'expo-dev-client';\n");
173
- writeFile(path.join(dir, 'app/index.tsx'), `${context.has('hono') ? "import { useEffect, useState } from 'react';\nimport { api } from '@/lib/api-client';\n" : ''}import { StatusBar } from 'expo-status-bar';
174
- import { Linking, ScrollView, StyleSheet, Text, View } from 'react-native';
90
+ writeFile(path.join(dir, 'app/index.tsx'), `import { useEffect, useState } from 'react';
91
+ import { api } from '@/lib/api-client';
92
+ import { StatusBar } from 'expo-status-bar';
93
+ import { Linking } from 'react-native';
94
+ import { Screen, Stack, Text } from '@workspace/native-ui';
175
95
  import { Button } from '@/components/ui/button';
176
96
 
177
97
  export default function HomeScreen() {
178
- ${context.has('hono')
179
- ? `const [connection, setConnection] = useState('Connecting to the API…');
98
+ const [connection, setConnection] = useState('Connecting to the API…');
180
99
  const [pending, setPending] = useState(true);
181
100
  useEffect(() => {
182
101
  let active = true;
@@ -193,46 +112,17 @@ export default function HomeScreen() {
193
112
  catch { setConnection('Unable to reach the API. Check the server and device API origin.'); }
194
113
  finally { setPending(false); }
195
114
  }
196
- `
197
- : ''}
198
- return (
199
- <ScrollView style={styles.screen} contentInsetAdjustmentBehavior="automatic" contentContainerStyle={styles.container}>
200
- <StatusBar style="auto" />
201
- <View style={styles.content}>
202
- <Text accessibilityRole="header" style={styles.title}>{${nameLiteral}}</Text>
203
- <Text selectable style={styles.subtitle}>Expo application scaffold generated by Anhedral.</Text>
204
- ${context.has('hono')
205
- ? `<Text accessibilityLiveRegion="polite">{connection}</Text>
206
- <Button disabled={pending} onPress={() => void checkConnection()}>{pending ? 'Connecting…' : 'Check API connection'}</Button>`
207
- : ''}
208
- <Button onPress={() => void Linking.openURL('https://docs.expo.dev')}>Learn more</Button>
209
- </View>
210
- </ScrollView>
211
- );
212
- }
213
115
 
214
- const styles = StyleSheet.create({
215
- screen: { flex: 1, backgroundColor: '#f8fafc' },
216
- container: { flexGrow: 1, justifyContent: 'center', padding: 32 },
217
- content: { gap: 12 },
218
- title: { color: '#0f172a', fontSize: 34, fontWeight: '700' },
219
- subtitle: { color: '#475569', fontSize: 17, paddingBottom: 12 },
220
- });
116
+ return <Screen><StatusBar style="auto" /><Stack>
117
+ <Text variant="heading" accessibilityRole="header">{${nameLiteral}}</Text>
118
+ <Text variant="muted">Native iOS and Android application generated by Anhedral.</Text>
119
+ <Text accessibilityLiveRegion="polite">{connection}</Text>
120
+ <Button disabled={pending} onPress={() => void checkConnection()}>{pending ? 'Connecting…' : 'Check API connection'}</Button>
121
+ <Button onPress={() => void Linking.openURL('https://docs.expo.dev')}>Learn more</Button>
122
+ </Stack></Screen>;
123
+ }
221
124
  `);
222
125
  writeFile(path.join(dir, '.env.example'), '');
223
- writeFile(path.join(dir, 'eas.json'), JSON.stringify({
224
- cli: { version: '>= 16.0.0' },
225
- build: {
226
- development: { developmentClient: true, distribution: 'internal' },
227
- preview: {
228
- environment: 'preview',
229
- distribution: 'internal',
230
- android: { buildType: 'apk' },
231
- },
232
- simulator: { environment: 'preview', ios: { simulator: true } },
233
- production: { environment: 'production', autoIncrement: true },
234
- },
235
- }, null, 2) + '\n');
236
126
  scaffoldExpoRuntime(context);
237
127
  appendGitignore(dir, [
238
128
  '.env',
@@ -0,0 +1,3 @@
1
+ import type { RecipeContext } from '../registry/types.js';
2
+ export declare function scaffoldWeb({ root, options, has }: 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,251 @@
1
+ import { initializeUiMetadata } from '../ui-project.js';
2
+ import { readFileSync } from 'node:fs';
3
+ import { fileURLToPath } from 'node:url';
4
+ import path from 'node:path';
5
+ import { resourceName, childPackageName, jsString } from '../render.js';
6
+ import { WEB_DEPENDENCIES } from '../dependencies.js';
7
+ import { json, put, workerConfig } from '../scaffold/files.js';
8
+ export function scaffoldWeb({ root, options, has }) {
9
+ const app = 'apps/web';
10
+ json(root, `${app}/package.json`, {
11
+ name: childPackageName(options.name, 'web'),
12
+ private: true,
13
+ version: '0.1.0',
14
+ type: 'module',
15
+ scripts: {
16
+ dev: 'next dev --turbopack --hostname 0.0.0.0 --port 3000',
17
+ 'build:next': 'next build --webpack',
18
+ build: 'opennextjs-cloudflare build && pnpm build:worker',
19
+ 'build:worker': 'wrangler deploy --dry-run --outdir dist',
20
+ preview: 'wrangler dev --port 3000 --inspector-port 9230',
21
+ deploy: 'wrangler deploy',
22
+ start: 'next start --hostname 0.0.0.0 --port 3000',
23
+ typecheck: 'next typegen && tsc --noEmit',
24
+ lint: 'eslint . --max-warnings 0',
25
+ },
26
+ dependencies: {
27
+ ...WEB_DEPENDENCIES.dependencies,
28
+ ...(has('hono') ? { '@workspace/contracts': 'workspace:*' } : {}),
29
+ '@workspace/styling': 'workspace:*',
30
+ },
31
+ devDependencies: {
32
+ ...WEB_DEPENDENCIES.devDependencies,
33
+ '@workspace/eslint-config': 'workspace:*',
34
+ },
35
+ });
36
+ json(root, `${app}/wrangler.jsonc`, {
37
+ ...workerConfig(resourceName(options.name, 'web')),
38
+ main: '.open-next/worker.js',
39
+ compatibility_flags: ['nodejs_compat', 'global_fetch_strictly_public'],
40
+ assets: { directory: '.open-next/assets', binding: 'ASSETS' },
41
+ services: [
42
+ ...(has('hono')
43
+ ? [{ binding: 'ANHEDRAL_API', service: resourceName(options.name, 'api') }]
44
+ : []),
45
+ { binding: 'WORKER_SELF_REFERENCE', service: resourceName(options.name, 'web') },
46
+ ],
47
+ });
48
+ put(root, `${app}/next.config.ts`, `import type { NextConfig } from 'next';
49
+ const previewOrigin = process.env.NODE_ENV === 'development' ? process.env.ANHEDRAL_PREVIEW_ORIGIN : undefined;
50
+ let allowedDevOrigins: string[] = [];
51
+ if (previewOrigin) {
52
+ const url = new URL(previewOrigin);
53
+ 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.');
54
+ allowedDevOrigins = [url.hostname];
55
+ }
56
+ const config: NextConfig = { allowedDevOrigins, transpilePackages: ${JSON.stringify(has('hono') ? ['@workspace/contracts', '@workspace/styling'] : ['@workspace/styling'])}, images: { unoptimized: true } };
57
+ export default config;
58
+ `);
59
+ put(root, `${app}/open-next.config.ts`, `import { defineCloudflareConfig } from '@opennextjs/cloudflare';
60
+ const config = { ...defineCloudflareConfig(), buildCommand: 'pnpm build:next' };
61
+ export default config;
62
+ `);
63
+ json(root, `${app}/tsconfig.json`, {
64
+ compilerOptions: {
65
+ target: 'ES2022',
66
+ lib: ['DOM', 'DOM.Iterable', 'ES2022'],
67
+ allowJs: true,
68
+ skipLibCheck: true,
69
+ strict: true,
70
+ noEmit: true,
71
+ esModuleInterop: true,
72
+ module: 'ESNext',
73
+ moduleResolution: 'Bundler',
74
+ resolveJsonModule: true,
75
+ isolatedModules: true,
76
+ jsx: 'react-jsx',
77
+ incremental: true,
78
+ plugins: [{ name: 'next' }],
79
+ paths: { '@/*': ['./*'] },
80
+ },
81
+ include: [
82
+ 'next-env.d.ts',
83
+ '**/*.ts',
84
+ '**/*.tsx',
85
+ '.next/types/**/*.ts',
86
+ '.next/dev/types/**/*.ts',
87
+ ],
88
+ exclude: ['node_modules', '.open-next', 'dist'],
89
+ });
90
+ put(root, `${app}/next-env.d.ts`, '/// <reference types="next" />\n/// <reference types="next/image-types/global" />\n');
91
+ put(root, `${app}/eslint.config.mjs`, `import { defineConfig, globalIgnores } from 'eslint/config';
92
+ import next from 'eslint-config-next/core-web-vitals';
93
+ import ts from 'eslint-config-next/typescript';
94
+ export default defineConfig([...next, ...ts, globalIgnores(['.next/**', '.open-next/**', 'dist/**', 'next-env.d.ts', 'worker-configuration.d.ts'])]);
95
+ `);
96
+ json(root, `${app}/components.json`, {
97
+ $schema: 'https://ui.shadcn.com/schema.json',
98
+ style: 'base-nova',
99
+ rsc: true,
100
+ tsx: true,
101
+ tailwind: { config: '', css: 'app/globals.css', baseColor: 'neutral', cssVariables: true },
102
+ aliases: {
103
+ components: '@/components',
104
+ ui: '@/components/ui',
105
+ utils: '@/lib/utils',
106
+ lib: '@/lib',
107
+ hooks: '@/hooks',
108
+ },
109
+ iconLibrary: 'lucide',
110
+ });
111
+ initializeUiMetadata(path.join(root, app), 'web');
112
+ put(root, `${app}/lib/utils.ts`, `import { clsx, type ClassValue } from 'clsx';
113
+ import { twMerge } from 'tailwind-merge';
114
+ export function cn(...values: ClassValue[]) { return twMerge(clsx(values)); }
115
+ `);
116
+ for (const component of ['button', 'input', 'label'])
117
+ put(root, `${app}/components/ui/${component}.tsx`, readFileSync(fileURLToPath(new URL(`../../assets/ui/web/${component}.tsx`, import.meta.url)), 'utf8'));
118
+ for (const file of ['LICENSE.shadcn', 'UPSTREAM.json'])
119
+ put(root, `${app}/${file}`, readFileSync(fileURLToPath(new URL(`../../assets/ui/${file}`, import.meta.url)), 'utf8'));
120
+ put(root, `${app}/postcss.config.mjs`, "const config = { plugins: { '@tailwindcss/postcss': {} } };\nexport default config;\n");
121
+ put(root, `${app}/app/globals.css`, `@import 'tailwindcss';
122
+ @import '@workspace/styling/globals.css';
123
+ @theme inline {
124
+ --color-background: hsl(var(--background)); --color-foreground: hsl(var(--foreground));
125
+ --color-primary: hsl(var(--primary)); --color-primary-foreground: hsl(var(--primary-foreground));
126
+ --color-secondary: hsl(var(--secondary)); --color-secondary-foreground: hsl(var(--secondary-foreground));
127
+ --color-muted: hsl(var(--muted)); --color-muted-foreground: hsl(var(--muted-foreground));
128
+ --color-border: hsl(var(--border)); --color-input: hsl(var(--input)); --color-ring: hsl(var(--ring));
129
+ --color-destructive: hsl(var(--destructive)); --radius-md: var(--radius); --radius-lg: calc(var(--radius) + 2px);
130
+ }
131
+
132
+ * { box-sizing: border-box; } body { margin: 0; background: hsl(var(--background)); color: hsl(var(--foreground)); font-family: Arial, Helvetica, sans-serif; }
133
+ 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; }
134
+ 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; }
135
+ a { color: inherit; } .button, input { min-height: 2.75rem; padding: .65rem 1rem; border: 1px solid hsl(var(--border)); border-radius: var(--radius); font: inherit; }
136
+ .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; }
137
+ :focus-visible { outline: 2px solid hsl(var(--ring)); outline-offset: 3px; } .muted { color: hsl(var(--muted-foreground)); }
138
+ `);
139
+ put(root, `${app}/app/layout.tsx`, `import type { Metadata } from 'next';
140
+ import Link from 'next/link';
141
+ import './globals.css';
142
+ export const metadata: Metadata = { title: ${jsString(options.name)}, description: 'Anhedral application' };
143
+ export default function Layout({ children }: { children: React.ReactNode }) { return <html lang="en"><body><main><nav aria-label="Main"><Link href="/">Home</Link></nav>{children}</main></body></html>; }
144
+ `);
145
+ put(root, `${app}/app/page.tsx`, `import { FoundationExample } from '@/components/foundation-example';
146
+ export default function Home() {
147
+ return <section className="stack"><h1>${escapeJsx(options.name)}</h1><p>Next.js on Cloudflare, with Anhedral UI.</p><p className="muted" data-rendering="server">Prerendered at build time; ready to hydrate in the browser.</p><FoundationExample /></section>;
148
+ }
149
+ `);
150
+ put(root, `${app}/components/foundation-example.tsx`, `'use client';
151
+ import { useState } from 'react';
152
+ import { Button } from '@/components/ui/button';
153
+ import { Input } from '@/components/ui/input';
154
+ import { Label } from '@/components/ui/label';
155
+ export function FoundationExample() {
156
+ const [idea, setIdea] = useState('My next application');
157
+ return <section className="stack"><Label htmlFor="idea">What will you build?</Label><Input id="idea" value={idea} onChange={event => setIdea(event.target.value)} /><p aria-live="polite">{idea}</p><Button onClick={() => setIdea('My next application')}>Reset example</Button></section>;
158
+ }
159
+ `);
160
+ put(root, `${app}/app/loading.tsx`, `export default function Loading() { return <p role="status">Loading…</p>; }\n`);
161
+ 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`);
162
+ put(root, `${app}/public/_headers`, '/_next/static/*\n Cache-Control: public, max-age=31536000, immutable\n/*\n X-Content-Type-Options: nosniff\n');
163
+ put(root, `${app}/public/robots.txt`, 'User-agent: *\nAllow: /\n');
164
+ if (!has('hono'))
165
+ return;
166
+ put(root, `${app}/lib/api-proxy.ts`, WEB_API_PROXY);
167
+ put(root, `${app}/lib/server-api.ts`, `import 'server-only';
168
+ import { getCloudflareContext } from '@opennextjs/cloudflare';
169
+ import { proxyApi, type ApiBinding } from './api-proxy';
170
+ function isApiBinding(value: unknown): value is ApiBinding {
171
+ return typeof value === 'object' && value !== null && typeof Reflect.get(value, 'fetch') === 'function';
172
+ }
173
+ async function productionBinding(): Promise<ApiBinding | undefined> {
174
+ const { env } = await getCloudflareContext({ async: true });
175
+ const candidate: unknown = Reflect.get(env, 'ANHEDRAL_API');
176
+ return isApiBinding(candidate) ? candidate : undefined;
177
+ }
178
+ export async function apiRequest(request: Request): Promise<Response> {
179
+ const development = process.env.NODE_ENV === 'development';
180
+ const binding = development ? undefined : await productionBinding();
181
+ return proxyApi(request, { binding, development, devOrigin: process.env.API_INTERNAL_URL });
182
+ }
183
+ `);
184
+ put(root, `${app}/app/api/[[...path]]/route.ts`, `import { apiRequest } from '@/lib/server-api';
185
+ export const dynamic = 'force-dynamic';
186
+ export const GET = apiRequest;
187
+ export const POST = apiRequest;
188
+ export const PUT = apiRequest;
189
+ export const PATCH = apiRequest;
190
+ export const DELETE = apiRequest;
191
+ export const HEAD = apiRequest;
192
+ export const OPTIONS = apiRequest;
193
+ `);
194
+ put(root, `${app}/.env.example`, '# Development only. Production uses the ANHEDRAL_API service binding.\nAPI_INTERNAL_URL=http://127.0.0.1:8787\n');
195
+ }
196
+ function escapeJsx(value) {
197
+ return value
198
+ .replaceAll('&', '&amp;')
199
+ .replaceAll('<', '&lt;')
200
+ .replaceAll('>', '&gt;')
201
+ .replaceAll('{', '&#123;')
202
+ .replaceAll('}', '&#125;');
203
+ }
204
+ export const WEB_API_PROXY = `export interface ApiBinding { fetch(request: Request): Promise<Response> }
205
+ type Options = { binding?: ApiBinding; development: boolean; devOrigin?: string; send?: typeof fetch };
206
+ function developmentOrigin(configured?: string): string {
207
+ const url = new URL(configured || 'http://127.0.0.1:8787');
208
+ const loopback = new Set(['127.0.0.1', 'localhost', '[::1]']);
209
+ const invalid = [url.protocol !== 'http:', !loopback.has(url.hostname), url.username, url.password, url.pathname !== '/', url.search, url.hash];
210
+ if (invalid.some(Boolean)) throw Error('API_INTERNAL_URL must be a loopback HTTP origin.');
211
+ return url.origin;
212
+ }
213
+ function backendOrigin(options: Options): string {
214
+ if (options.development) return developmentOrigin(options.devOrigin);
215
+ if ([!options.binding, options.devOrigin].some(Boolean)) throw Error('Production requires the API service binding.');
216
+ return 'https://api.internal';
217
+ }
218
+ function apiTarget(request: Request, origin: string): URL {
219
+ const url = new URL(request.url);
220
+ if (!/^\\/api(?:\\/|$)/.test(url.pathname)) throw Error('Unexpected API path.');
221
+ return new URL(url.pathname + url.search, origin);
222
+ }
223
+ function forwardedHeaders(request: Request): Headers {
224
+ const headers = new Headers();
225
+ for (const name of ['accept', 'content-type', 'cookie', 'origin', 'authorization', 'sec-fetch-site', 'expo-origin', 'idempotency-key']) {
226
+ const value = request.headers.get(name); if (value) headers.set(name, value);
227
+ }
228
+ return headers;
229
+ }
230
+ function upstreamRequest(request: Request, target: URL): Request {
231
+ const settings: RequestInit & { duplex?: 'half' } = { method: request.method, headers: forwardedHeaders(request), redirect: 'manual', signal: AbortSignal.any([request.signal, AbortSignal.timeout(15000)]) };
232
+ if (!['GET', 'HEAD'].includes(request.method)) { settings.body = request.body; settings.duplex = 'half'; }
233
+ return new Request(target, settings);
234
+ }
235
+ function privateResponse(response: Response, development: boolean): Response {
236
+ const headers = new Headers(response.headers);
237
+ for (const name of ['connection', 'transfer-encoding', 'access-control-allow-origin', 'access-control-allow-credentials']) headers.delete(name);
238
+ // Node fetch already decoded the local HTTP response. Next must frame/compress
239
+ // those decoded bytes itself; the sidecar's wire headers no longer describe them.
240
+ if (development) { headers.delete('content-encoding'); headers.delete('content-length'); }
241
+ headers.set('cache-control', 'private, no-store');
242
+ return new Response(response.body, { status: response.status, headers });
243
+ }
244
+ export async function proxyApi(request: Request, options: Options): Promise<Response> {
245
+ try {
246
+ const upstream = upstreamRequest(request, apiTarget(request, backendOrigin(options)));
247
+ const response = options.development ? await (options.send ?? fetch)(upstream) : await options.binding!.fetch(upstream);
248
+ return privateResponse(response, options.development);
249
+ } catch { return Response.json({ error: 'API unavailable' }, { status: 503, headers: { 'cache-control': 'private, no-store' } }); }
250
+ }
251
+ `;
@@ -1,14 +1,3 @@
1
1
  export declare const PROJECT_CONFIG_FILE = "anhedral.json";
2
- export declare const PROJECT_CONFIG_MAX_BYTES: number;
3
- export declare const PROJECT_CONFIG_SECTIONS: readonly ["identity", "standard", "setup", "providers", "cloudflare", "vercel", "registry"];
4
- export type ProjectSection = (typeof PROJECT_CONFIG_SECTIONS)[number];
5
- export type ProjectConfig = {
6
- schemaVersion: 1;
7
- } & Partial<Record<ProjectSection, unknown>>;
8
- /** Validate the envelope independently; each domain validates its own selected section. */
9
- export declare function parseProjectConfig(value: unknown): ProjectConfig;
10
- export declare function projectConfigPath(root: string): string;
11
- export declare function readProjectConfig(root: string): ProjectConfig;
12
- export declare function hasProjectSection(root: string, section: ProjectSection): boolean;
13
- export declare function readProjectSection<T = any>(root: string, section: ProjectSection): T;
14
- export declare function writeProjectSection(root: string, section: ProjectSection, value: unknown): void;
2
+ /** Called only inside a fresh staged workspace. Contains nonsecret generation provenance. */
3
+ export declare function writeProjectSection(root: string, section: string, value: unknown): void;
@@ -1,89 +1,16 @@
1
- import { randomUUID } from 'node:crypto';
2
- import { lstatSync, readFileSync, renameSync, rmSync, writeFileSync } from 'node:fs';
1
+ import { readFileSync, writeFileSync } from 'node:fs';
3
2
  import path from 'node:path';
4
- import { withSourceWriteLock } from './transaction.js';
5
- import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from './bounded-file.js';
6
3
  export const PROJECT_CONFIG_FILE = 'anhedral.json';
7
- export const PROJECT_CONFIG_MAX_BYTES = MAX_PROJECT_JSON_BYTES;
8
- export const PROJECT_CONFIG_SECTIONS = [
9
- 'identity',
10
- 'standard',
11
- 'setup',
12
- 'providers',
13
- 'cloudflare',
14
- 'vercel',
15
- 'registry',
16
- ];
17
- /** Validate the envelope independently; each domain validates its own selected section. */
18
- export function parseProjectConfig(value) {
19
- if (!value ||
20
- typeof value !== 'object' ||
21
- Array.isArray(value) ||
22
- value.schemaVersion !== 1 ||
23
- Object.keys(value).some((key) => key !== 'schemaVersion' && !PROJECT_CONFIG_SECTIONS.includes(key)))
24
- throw new Error('Invalid anhedral.json configuration.');
25
- return value;
26
- }
27
- export function projectConfigPath(root) {
28
- return path.join(root, PROJECT_CONFIG_FILE);
29
- }
30
- export function readProjectConfig(root) {
31
- const source = readBoundedFile(projectConfigPath(root), PROJECT_CONFIG_MAX_BYTES).toString('utf8');
32
- try {
33
- return parseProjectConfig(JSON.parse(source));
34
- }
35
- catch {
36
- throw new Error('Invalid anhedral.json configuration.');
37
- }
38
- }
39
- function assertSection(section) {
40
- if (!PROJECT_CONFIG_SECTIONS.includes(section))
41
- throw new Error('Unknown anhedral.json section.');
42
- }
43
- export function hasProjectSection(root, section) {
44
- assertSection(section);
45
- if (!lstatSync(projectConfigPath(root), { throwIfNoEntry: false }))
46
- return false;
47
- return Object.hasOwn(readProjectConfig(root), section);
48
- }
49
- // Domain callers retain responsibility for validating their complete section contracts.
50
- export function readProjectSection(root, section) {
51
- assertSection(section);
52
- const value = readProjectConfig(root)[section];
53
- if (!value || typeof value !== 'object' || Array.isArray(value))
54
- throw new Error(`Missing or invalid anhedral.json ${section} section.`);
55
- return value;
56
- }
57
- /** Atomically replace one section while preserving other domains' configuration. */
58
- function writeSection(root, section, value) {
59
- assertSection(section);
60
- if (!value || typeof value !== 'object' || Array.isArray(value))
61
- throw new Error(`Invalid anhedral.json ${section} section.`);
62
- const file = projectConfigPath(root);
63
- const previous = lstatSync(file, { throwIfNoEntry: false }) ? readProjectConfig(root) : {};
64
- const config = { ...previous, schemaVersion: 1, [section]: value };
65
- const ordered = {
66
- schemaVersion: 1,
67
- ...Object.fromEntries(PROJECT_CONFIG_SECTIONS.filter((key) => Object.hasOwn(config, key)).map((key) => [
68
- key,
69
- config[key],
70
- ])),
71
- };
72
- const bytes = JSON.stringify(ordered, null, 2) + '\n';
73
- if (Buffer.byteLength(bytes) > PROJECT_CONFIG_MAX_BYTES)
74
- throw new Error('anhedral.json exceeds its size limit.');
75
- // Avoid changing source bytes or permissions when the requested section is unchanged.
76
- if (lstatSync(file, { throwIfNoEntry: false }) && readFileSync(file, 'utf8') === bytes)
77
- return;
78
- const temporary = `${file}.${randomUUID()}.tmp`;
4
+ /** Called only inside a fresh staged workspace. Contains nonsecret generation provenance. */
5
+ export function writeProjectSection(root, section, value) {
6
+ const file = path.join(root, PROJECT_CONFIG_FILE);
7
+ let previous = {};
79
8
  try {
80
- writeFileSync(temporary, bytes, { mode: 0o600, flag: 'wx' });
81
- renameSync(temporary, file);
9
+ previous = JSON.parse(readFileSync(file, 'utf8'));
82
10
  }
83
- finally {
84
- rmSync(temporary, { force: true });
11
+ catch (error) {
12
+ if (error.code !== 'ENOENT')
13
+ throw error;
85
14
  }
86
- }
87
- export function writeProjectSection(root, section, value) {
88
- withSourceWriteLock(root, () => writeSection(root, section, value));
15
+ writeFileSync(file, JSON.stringify({ ...previous, schemaVersion: 1, [section]: value }, null, 2) + '\n');
89
16
  }
@@ -4,7 +4,6 @@ export function createRecipeContext(root, options) {
4
4
  root,
5
5
  options,
6
6
  has: (product) => selected.has(product),
7
- runtimeApp: selected.has('hono') ? 'api' : 'web',
8
7
  bindings: {},
9
8
  };
10
9
  }