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
@@ -1,328 +0,0 @@
1
- import { NATIVE_ESLINT_VERSION } from '../dependencies.js';
2
- import path from 'node:path';
3
- import { writeReactLintConfig } from './lint.js';
4
- import { writeFile } from '../util.js';
5
- import { EXTENSION_DEPENDENCIES } from '../dependencies.js';
6
- import { childPackageName, htmlText, jsString, markdownHeading } from '../render.js';
7
- export async function scaffoldWxt({ root, options }) {
8
- const projectName = options.name;
9
- const displayName = options.name;
10
- const dir = path.join(root, 'apps/extension');
11
- writePackageJson(dir, projectName);
12
- writeFile(path.join(dir, 'tsconfig.json'), JSON.stringify({
13
- extends: './.wxt/tsconfig.json',
14
- compilerOptions: { strict: true, jsx: 'react-jsx', paths: { '@/*': ['./src/*'] } },
15
- }, null, 2) + '\n');
16
- writeReactLintConfig(dir);
17
- writeWxtConfig(dir, displayName);
18
- writeEnvExample(dir);
19
- writePostcssConfig(dir);
20
- writeTailwindConfig(dir);
21
- writeShadcnConfig(dir);
22
- writeReadme(dir, displayName);
23
- writeCnUtil(dir);
24
- writeButtonComponent(dir);
25
- writeBackground(dir);
26
- writeSidepanelEntry(dir);
27
- writeSidepanelHtml(dir, displayName);
28
- writeSidepanelApp(dir);
29
- writeStyles(dir);
30
- }
31
- function writePackageJson(dir, projectName) {
32
- writeFile(path.join(dir, 'package.json'), JSON.stringify({
33
- name: childPackageName(projectName, 'chrome-ext'),
34
- version: '0.1.0',
35
- private: true,
36
- type: 'module',
37
- scripts: {
38
- dev: 'wxt',
39
- build: 'wxt build',
40
- postinstall: 'wxt prepare',
41
- zip: 'wxt zip',
42
- typecheck: 'tsc --noEmit',
43
- lint: 'eslint src --max-warnings 0',
44
- },
45
- dependencies: {
46
- ...EXTENSION_DEPENDENCIES.dependencies,
47
- '@workspace/styling': 'workspace:*',
48
- },
49
- devDependencies: {
50
- ...EXTENSION_DEPENDENCIES.devDependencies,
51
- '@workspace/eslint-config': 'workspace:*',
52
- eslint: NATIVE_ESLINT_VERSION,
53
- },
54
- }, null, 2) + '\n');
55
- }
56
- function writeWxtConfig(dir, displayName) {
57
- const nameLiteral = jsString(displayName);
58
- const descriptionLiteral = jsString(`${displayName} Chrome Extension`);
59
- const actionTitleLiteral = jsString(`Open ${displayName}`);
60
- writeFile(path.join(dir, 'wxt.config.ts'), `import { defineConfig } from 'wxt';
61
-
62
- export default defineConfig({
63
- srcDir: 'src',
64
- dev: { server: { port: 3001, strictPort: true } },
65
- manifest: () => {
66
- const crxPublicKey = import.meta.env.VITE_CRX_PUBLIC_KEY || '';
67
-
68
- return {
69
- name: ${nameLiteral},
70
- description: ${descriptionLiteral},
71
- version: '0.1.0',
72
- ...(crxPublicKey ? { key: crxPublicKey } : {}),
73
- minimum_chrome_version: '114',
74
- permissions: ['activeTab', 'scripting', 'sidePanel'],
75
- host_permissions: [],
76
- action: {
77
- default_title: ${actionTitleLiteral},
78
- },
79
- side_panel: {
80
- default_path: 'sidepanel.html',
81
- },
82
- };
83
- },
84
- modules: ['@wxt-dev/module-react'],
85
- vite: () => ({
86
- build: {
87
- chunkSizeWarningLimit: 3000,
88
- },
89
- }),
90
- });
91
- `);
92
- }
93
- function extensionEnvContents() {
94
- const sections = [];
95
- sections.push(`# Chrome Extension CRX public key (optional, for stable extension ID)
96
- VITE_CRX_PUBLIC_KEY=`);
97
- return `${sections.join('\n\n')}\n`;
98
- }
99
- function writeEnvExample(dir) {
100
- writeFile(path.join(dir, '.env.example'), extensionEnvContents());
101
- }
102
- function writePostcssConfig(dir) {
103
- writeFile(path.join(dir, 'postcss.config.cjs'), `module.exports = {
104
- plugins: {
105
- tailwindcss: {},
106
- autoprefixer: {},
107
- },
108
- };
109
- `);
110
- }
111
- function writeShadcnConfig(dir) {
112
- writeFile(path.join(dir, 'components.json'), JSON.stringify({
113
- $schema: 'https://ui.shadcn.com/schema.json',
114
- style: 'new-york',
115
- rsc: false,
116
- tsx: true,
117
- tailwind: {
118
- config: '',
119
- css: 'src/styles/main.css',
120
- baseColor: 'neutral',
121
- cssVariables: true,
122
- prefix: '',
123
- },
124
- aliases: {
125
- components: '@/components',
126
- utils: '@/lib/utils',
127
- ui: '@/components/ui',
128
- lib: '@/lib',
129
- hooks: '@/hooks',
130
- },
131
- iconLibrary: 'lucide',
132
- }, null, 2) + '\n');
133
- }
134
- function writeCnUtil(dir) {
135
- writeFile(path.join(dir, 'src/lib/utils.ts'), `import { clsx, type ClassValue } from 'clsx';
136
- import { twMerge } from 'tailwind-merge';
137
-
138
- export function cn(...inputs: ClassValue[]) {
139
- return twMerge(clsx(inputs));
140
- }
141
- `);
142
- }
143
- function writeButtonComponent(dir) {
144
- writeFile(path.join(dir, 'src/components/ui/button.tsx'), `import * as React from 'react';
145
- import { cn } from '@/lib/utils';
146
-
147
- type ButtonVariant = 'default' | 'outline';
148
-
149
- type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
150
- variant?: ButtonVariant;
151
- };
152
-
153
- const variantClasses: Record<ButtonVariant, string> = {
154
- default: 'bg-primary text-primary-foreground hover:bg-primary/90',
155
- outline: 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
156
- };
157
-
158
- export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
159
- ({ className, variant = 'default', type = 'button', ...props }, ref) => {
160
- return (
161
- <button
162
- ref={ref}
163
- type={type}
164
- className={cn(
165
- 'inline-flex h-9 items-center justify-center whitespace-nowrap rounded-md px-4 py-2 text-sm font-medium transition-colors disabled:pointer-events-none disabled:opacity-50',
166
- variantClasses[variant],
167
- className,
168
- )}
169
- {...props}
170
- />
171
- );
172
- },
173
- );
174
-
175
- Button.displayName = 'Button';
176
- `);
177
- }
178
- function writeTailwindConfig(dir) {
179
- writeFile(path.join(dir, 'tailwind.config.cjs'), `/** @type {import('tailwindcss').Config} */
180
- module.exports = {
181
- content: ['./src/**/*.{ts,tsx,html}'],
182
- presets: [require('@workspace/styling/tailwind')],
183
- };
184
- `);
185
- }
186
- function writeReadme(dir, displayName) {
187
- writeFile(path.join(dir, 'README.md'), `# ${markdownHeading(displayName)} Chrome Extension
188
-
189
- WXT side-panel extension generated by anhedral.
190
-
191
- ## Development
192
-
193
- \`\`\`bash
194
- cp .env.example .env
195
- pnpm dev
196
- pnpm build
197
- pnpm zip
198
- \`\`\`
199
-
200
- Run these commands from \`apps/extension\`. Anhedral generates only \`.env.example\`; keep the local \`.env\` file uncommitted. Set \`VITE_CRX_PUBLIC_KEY\` only when you need a stable Chrome extension ID.
201
-
202
- ## Chrome
203
-
204
- Run \`pnpm build\`, then load \`.output/chrome-mv3\` as an unpacked extension from \`chrome://extensions\`.
205
-
206
- The extension uses Chrome's Side Panel API. The browser action opens \`sidepanel.html\`, \`wxt.config.ts\` declares the \`sidePanel\` permission and Chrome 114+ minimum version, and active-page reads use a user-triggered \`activeTab\` + \`scripting\` grant instead of persistent site access.
207
- `);
208
- }
209
- function writeBackground(dir) {
210
- writeFile(path.join(dir, 'src/entrypoints/background.ts'), `type ChromeWithSidePanel = typeof chrome & {
211
- sidePanel: {
212
- setPanelBehavior: (behavior: { openPanelOnActionClick: boolean }) => Promise<void>;
213
- };
214
- };
215
-
216
- export default defineBackground(() => {
217
-
218
- // Open the side panel when the extension icon is clicked.
219
- (chrome as ChromeWithSidePanel).sidePanel
220
- .setPanelBehavior({ openPanelOnActionClick: true })
221
- .catch((error) => console.error('Unable to configure the side panel:', error));
222
- });
223
- `);
224
- }
225
- function writeSidepanelEntry(dir) {
226
- writeFile(path.join(dir, 'src/entrypoints/sidepanel/main.tsx'), `import * as React from 'react';
227
- import { createRoot } from 'react-dom/client';
228
- import { SidePanelApp } from './app';
229
- import '../../styles/main.css';
230
-
231
- const container = document.getElementById('root');
232
- if (container) {
233
- const root = createRoot(container);
234
- root.render(
235
- <React.StrictMode>
236
- <SidePanelApp />
237
- </React.StrictMode>
238
- );
239
- }
240
- `);
241
- }
242
- function writeSidepanelHtml(dir, displayName) {
243
- writeFile(path.join(dir, 'src/entrypoints/sidepanel/index.html'), `<!DOCTYPE html>
244
- <html lang="en">
245
- <head>
246
- <meta charset="UTF-8" />
247
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
248
- <title>${htmlText(displayName)}</title>
249
- </head>
250
- <body>
251
- <div id="root"></div>
252
- <script type="module" src="./main.tsx"></script>
253
- </body>
254
- </html>
255
- `);
256
- }
257
- function writeSidepanelApp(dir) {
258
- writeFile(path.join(dir, 'src/entrypoints/sidepanel/app.tsx'), `import * as React from 'react';
259
- import { Button } from '../../components/ui/button';
260
-
261
- type PageSnapshot = {
262
- title: string;
263
- location: string;
264
- };
265
-
266
- async function readPageSnapshot(): Promise<PageSnapshot> {
267
- const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
268
- if (!tab?.id) throw new Error('No active tab is available.');
269
- const [{ result }] = await chrome.scripting.executeScript({
270
- target: { tabId: tab.id },
271
- func: () => ({ title: document.title, location: window.location.href }),
272
- });
273
- if (!result) throw new Error('The active page did not return a snapshot.');
274
- return result as PageSnapshot;
275
- }
276
-
277
- export function SidePanelApp() {
278
- const [page, setPage] = React.useState<PageSnapshot | null>(null);
279
- const [pageError, setPageError] = React.useState<string | null>(null);
280
-
281
- const readActivePage = React.useCallback(async () => {
282
- setPageError(null);
283
- try {
284
- setPage(await readPageSnapshot());
285
- } catch {
286
- setPageError('Chrome does not allow this page to be inspected. Open a normal website and try again.');
287
- }
288
- }, []);
289
-
290
- return (
291
- <div style={{ padding: 24 }}>
292
- <h2>Welcome!</h2>
293
- <Button type="button" onClick={() => void readActivePage()}>Read active page</Button>
294
- {page ? (
295
- <div role="status" aria-live="polite" style={{ marginTop: 16 }}>
296
- <strong>{page.title || 'Untitled page'}</strong>
297
- <p style={{ overflowWrap: 'anywhere' }}>{page.location}</p>
298
- </div>
299
- ) : null}
300
- {pageError ? <p role="alert" aria-live="assertive" style={{ color: 'hsl(var(--destructive))' }}>{pageError}</p> : null}
301
- </div>
302
- );
303
- }
304
- `);
305
- }
306
- function writeStyles(dir) {
307
- writeFile(path.join(dir, 'src/styles/main.css'), `@tailwind base;
308
- @tailwind components;
309
- @tailwind utilities;
310
-
311
- @layer base {
312
-
313
- * {
314
- border-color: hsl(var(--border));
315
- }
316
-
317
- body {
318
- background: hsl(var(--background));
319
- color: hsl(var(--foreground));
320
- }
321
- }
322
-
323
- body {
324
- margin: 0;
325
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
326
- }
327
- `);
328
- }
@@ -1,4 +0,0 @@
1
- /** Fresh bootstrap only: framework-specific lint tooling belongs to its app. */
2
- export declare function normalizeSharedLint(root: string): void;
3
- /** Keep the starter's React/TypeScript rules and add the web app's Next API rules. */
4
- export declare function writeWebLint(root: string): void;
@@ -1,56 +0,0 @@
1
- import { existsSync, rmSync } from 'node:fs';
2
- import path from 'node:path';
3
- import { json, put, readJson } from './files.js';
4
- /** Fresh bootstrap only: framework-specific lint tooling belongs to its app. */
5
- export function normalizeSharedLint(root) {
6
- const file = 'packages/eslint-config/package.json';
7
- if (!existsSync(path.join(root, file)))
8
- return;
9
- const manifest = readJson(root, file);
10
- for (const group of [
11
- 'dependencies',
12
- 'devDependencies',
13
- 'peerDependencies',
14
- 'optionalDependencies',
15
- ]) {
16
- const dependencies = manifest[group];
17
- if (dependencies && typeof dependencies === 'object' && !Array.isArray(dependencies))
18
- delete dependencies['@next/eslint-plugin-next'];
19
- }
20
- if (manifest.exports && typeof manifest.exports === 'object' && !Array.isArray(manifest.exports))
21
- delete manifest.exports['./next-js'];
22
- json(root, file, manifest);
23
- rmSync(path.join(root, 'packages/eslint-config/next.js'), { force: true });
24
- }
25
- /** Keep the starter's React/TypeScript rules and add the web app's Next API rules. */
26
- export function writeWebLint(root) {
27
- put(root, 'apps/web/eslint.config.js', `import { globalIgnores } from 'eslint/config';
28
- import pluginNext from '@next/eslint-plugin-next';
29
- import typescriptParser from '@typescript-eslint/parser';
30
- import typescriptPlugin from '@typescript-eslint/eslint-plugin';
31
- import { config as reactConfig } from '@workspace/eslint-config/react-internal';
32
-
33
- export default [
34
- ...reactConfig,
35
- {
36
- files: ['**/*.{js,jsx,mjs,cjs,ts,tsx}'],
37
- languageOptions: { parser: typescriptParser, parserOptions: { ecmaFeatures: { jsx: true } } },
38
- plugins: { '@typescript-eslint': typescriptPlugin },
39
- rules: { 'no-unused-vars': 'off', '@typescript-eslint/no-unused-vars': 'error' },
40
- },
41
- {
42
- files: ['**/*.{ts,tsx}'],
43
- // TypeScript checks undefined names; ESLint's core rule cannot model types.
44
- rules: { 'no-undef': 'off' },
45
- },
46
- globalIgnores(['.next/**', 'out/**', 'build/**', 'next-env.d.ts', '.open-next/**', '.wrangler/**', '.void/**', 'dist/**', 'cloudflare-env.d.ts']),
47
- {
48
- plugins: { '@next/next': pluginNext },
49
- rules: {
50
- ...pluginNext.configs.recommended.rules,
51
- ...pluginNext.configs['core-web-vitals'].rules,
52
- },
53
- },
54
- ];
55
- `);
56
- }
@@ -1,2 +0,0 @@
1
- import type { RecipeContext } from '../registry/types.js';
2
- export declare function scaffoldNeonRealtime({ root, options, runtimeApp }: RecipeContext): void;
@@ -1,97 +0,0 @@
1
- import { rmSync } from 'node:fs';
2
- import path from 'node:path';
3
- import { STACK_DEPENDENCIES } from '../dependencies.js';
4
- import { patchPackage, put, sharedPackage } from './files.js';
5
- import { writeEnvironmentFile } from './environment.js';
6
- export function scaffoldNeonRealtime({ root, options, runtimeApp }) {
7
- const directory = 'packages/neon-realtime';
8
- sharedPackage(root, 'neon-realtime', '', {
9
- '@neon/realtime': STACK_DEPENDENCIES['@neon/realtime'],
10
- '@neon/realtime-drizzle': STACK_DEPENDENCIES['@neon/realtime-drizzle'],
11
- 'drizzle-orm': STACK_DEPENDENCIES['drizzle-orm'],
12
- });
13
- rmSync(path.join(root, directory, 'src/index.ts'));
14
- patchPackage(root, `${directory}/package.json`, {
15
- exports: { './server': './src/server.ts', './client': './src/client.ts' },
16
- });
17
- put(root, `${directory}/src/server.ts`, `import { createRealtime } from '@neon/realtime/server';
18
- import { drizzleAdapter } from '@neon/realtime-drizzle';
19
-
20
- function databaseName(connectionString: string): string {
21
- let database: string;
22
- try {
23
- const url = new URL(connectionString);
24
- if (!['postgres:', 'postgresql:'].includes(url.protocol)) throw new Error();
25
- database = decodeURIComponent(url.pathname.slice(1));
26
- if (!/^[^/]+$/.test(database)) throw new Error();
27
- } catch {
28
- throw new Error('Configure a PostgreSQL DATABASE_URL with the intended database name.');
29
- }
30
- return database;
31
- }
32
-
33
- // Import this entry point only from server code. Sealing is local Web Crypto work.
34
- export function createNeonRealtime(options: { secret: string; databaseUrl: string }) {
35
- if (!options.secret.trim()) throw new Error('Configure the branch NEON_REALTIME_SECRET on the server.');
36
- return createRealtime({ secret: options.secret, db: databaseName(options.databaseUrl), adapter: drizzleAdapter() });
37
- }
38
- `);
39
- put(root, `${directory}/src/client.ts`, `import { createRealtimeClient } from '@neon/realtime/client';
40
- import { drizzleParsers } from '@neon/realtime-drizzle/client';
41
-
42
- export type { SealedLiveQuery, LiveQuerySnapshot, LiveQueryState } from '@neon/realtime/client';
43
-
44
- // One client per database; close it on sign-out and unsubscribe on component cleanup.
45
- export function createNeonRealtimeClient(url: string) {
46
- return createRealtimeClient({ url, parsers: { ...drizzleParsers } });
47
- }
48
- `);
49
- const app = `apps/${runtimeApp}`;
50
- const native = runtimeApp === 'web' && options.hosting === 'vercel';
51
- writeEnvironmentFile(root, `${app}/${native ? '.env.example' : '.dev.vars.example'}`, {
52
- NEON_REALTIME_SECRET: '',
53
- });
54
- if (!native)
55
- put(root, `${app}/${runtimeApp === 'api' ? 'src/' : ''}neon-realtime-secrets.d.ts`, runtimeApp === 'api'
56
- ? 'interface Env { NEON_REALTIME_SECRET: string }\n'
57
- : 'declare namespace Cloudflare { interface Env { NEON_REALTIME_SECRET: string } }\n');
58
- put(root, `${directory}/README.md`, neonRealtimeGuide);
59
- }
60
- const neonRealtimeGuide = `# Neon Realtime (beta)
61
-
62
- This package streams PostgreSQL SELECT results through Neon's managed Realtime service. It shares packages/db and does not create a second database or Worker. The separate --realtime option creates Cloudflare Durable Object WebSocket rooms; both options can coexist.
63
-
64
- ## Branch setup
65
-
66
- Enable Realtime on the intended Neon branch using the Neon Console or neon realtime enable. This is a manual operation; Anhedral's Neon database provisioning does not enable Realtime. Check beta availability first: aws-us-east-1, aws-us-east-2, aws-eu-central-1 and aws-ap-southeast-1 (reviewed 2026-10-16). Claimed projects only. Enabling Realtime requires logical replication; review this change before applying it. Configure the service's allowedOrigins for the exact development and production browser origins.
67
-
68
- Copy that branch's NEON_REALTIME_SECRET into the selected server app's ignored runtime file using its generated environment example. Use .env.local for native Next.js on Vercel, .env for Void, or .dev.vars for Wrangler. For anhedral ship, use file permissions 0600. Keep the database URL and secret on the server, in the same branch/environment. The root .env.example is an inventory, not an automatically loaded runtime file. Store all Anhedral project settings in the existing anhedral.json; no additional provider config file is needed.
69
-
70
- NEON_REALTIME_URL is a public transport URL from the branch's Realtime page. Pass it explicitly to the client factory or expose only that URL through the frontend's public build environment (NEXT_PUBLIC_NEON_REALTIME_URL for web; use the platform's public prefix elsewhere). Never prefix the secret or DATABASE_URL with NEXT_PUBLIC_, VITE_ or EXPO_PUBLIC_. No public sealing route is generated.
71
-
72
- ## Server integration
73
-
74
- Add @workspace/neon-realtime and @workspace/db as workspace:* dependencies of the server app when implementing product routes. Import createNeonRealtime from @workspace/neon-realtime/server and createDatabase from @workspace/db. Pass { secret: env.NEON_REALTIME_SECRET, databaseUrl: env.DATABASE_URL } to createNeonRealtime; use the existing database factory to build Drizzle selects. The Realtime adapter compiles queries without executing them through the HTTP driver; normal writes and migrations still use packages/db.
75
-
76
- Authenticate each sealing request with the selected identity system. Validate request parameters, derive the user identity from the verified session, and build a bounded SELECT scoped to that user's rows or membership joins. Then call await realtime.seal({ query }) and return its JSON with Cache-Control: private, no-store over HTTPS. Do not accept SQL or an owner ID from the browser, cache sealed queries across users, or expose secret-bearing configuration. Recheck authentication and authorization on every renewal. Never subscribe to auth/session/credential tables.
77
-
78
- Tables need stable replica identity (normally a primary key). Queries must be read-only and deterministic: functions such as now() cannot be used in live selects. Selected Drizzle keys must match SQL result column names; alias camelCase/computed fields explicitly. Use drizzleParsers from this package's client factory so dates/timestamps agree with Drizzle's types. RLS is not supported in the beta: put access rules in the query itself, including live membership joins when immediate membership revocation is required.
79
-
80
- ## Client lifecycle
81
-
82
- Add @workspace/neon-realtime as a workspace:* dependency of each client app. Import createNeonRealtimeClient and the SealedLiveQuery row type from @workspace/neon-realtime/client. This entry point contains no server factory, ORM or credentials. Create one client per database with the public URL. Fetch a sealed query from your authenticated endpoint, then call client.subscribe(sealedQuery) and subscription.onChange(render). Snapshots include connecting/live/stale/error/closed state; surface errors and stale data in the UI.
83
-
84
- Capabilities currently expire after 60 seconds. Schedule an authenticated refresh before expiresAt and call subscription.renew(next); use the returned expiry for the next refresh. A changed query or parameters require a new subscription. Stop renewal timers and call subscription.unsubscribe() on unmount; close the shared client on sign-out to clear subscriptions and user data. Treat terminal errors separately from reconnects. Sealed queries are bearer credentials until expiry: keep them out of URLs, logs and persistent browser storage. The optional upstream React and TanStack bindings can manage renewal; they are not dependencies of this framework-neutral package.
85
-
86
- ## Acceptance
87
-
88
- Test two users with disjoint rows, denied/expired sessions and renewal, membership removal during a subscription, query/parameter changes, stale/error states, reconnects and cleanup. Apply reviewed schema migrations separately. No service is enabled or deployed by init. The beta transport may change and has no performance guarantees. Realtime is free during beta, but database compute and egress can incur charges.
89
-
90
- Official references:
91
-
92
- - https://neon.com/docs/realtime/overview
93
- - https://neon.com/docs/realtime/quickstart
94
- - https://neon.com/docs/realtime/guides/queries
95
- - https://neon.com/docs/realtime/guides/subscribing
96
- - https://neon.com/docs/realtime/examples/drizzle
97
- `;
@@ -1,5 +0,0 @@
1
- import type { RecipeContext } from '../registry/types.js';
2
- export declare function scaffoldRealtime({ root, options }: RecipeContext): void;
3
- export declare function scaffoldQueues({ root, options }: RecipeContext): void;
4
- export declare function scaffoldCron({ root, options }: RecipeContext): void;
5
- export declare function scaffoldWorkflows({ root, options }: RecipeContext): void;
@@ -1,108 +0,0 @@
1
- import { resourceName } from '../render.js';
2
- import { workerConfig, worker } from './files.js';
3
- export function scaffoldRealtime({ root, options }) {
4
- worker(root, 'realtime', {
5
- ...workerConfig(resourceName(options.name, 'realtime')),
6
- durable_objects: { bindings: [{ name: 'ROOMS', class_name: 'Room' }] },
7
- migrations: [{ tag: 'v1', new_sqlite_classes: ['Room'] }],
8
- }, `import { DurableObject } from 'cloudflare:workers';
9
- export class Room extends DurableObject<Env> {
10
- async fetch(request: Request): Promise<Response> {
11
- if (request.headers.get('Upgrade')?.toLowerCase() !== 'websocket') {
12
- return new Response('WebSocket required', { status: 426 });
13
- }
14
- const pair = new WebSocketPair();
15
- this.ctx.acceptWebSocket(pair[1]);
16
- return new Response(null, { status: 101, webSocket: pair[0] });
17
- }
18
- webSocketMessage(sender: WebSocket, message: string | ArrayBuffer) {
19
- const size = typeof message === 'string'
20
- ? new TextEncoder().encode(message).byteLength
21
- : message.byteLength;
22
- if (size > 16384) {
23
- sender.close(1009, 'Message too large');
24
- return;
25
- }
26
- this.#broadcastToPeers(sender, message);
27
- }
28
-
29
- #broadcastToPeers(sender: WebSocket, message: string | ArrayBuffer) {
30
- for (const socket of this.ctx.getWebSockets()) {
31
- if (socket !== sender) socket.send(message);
32
- }
33
- }
34
- }
35
- export default {
36
- async fetch(): Promise<Response> {
37
- // Authenticate and authorize room membership, then forward to env.ROOMS.getByName(room).fetch(request).
38
- // Use short-lived single-use tickets for browser WebSockets. Never expose a long-lived service secret.
39
- return new Response('Configure room authorization before enabling connections', { status: 501 });
40
- },
41
- };
42
- `);
43
- }
44
- export function scaffoldQueues({ root, options }) {
45
- worker(root, 'jobs', {
46
- ...workerConfig(resourceName(options.name, 'jobs')),
47
- queues: {
48
- producers: [{ binding: 'JOBS', queue: resourceName(options.name, 'jobs') }],
49
- consumers: [
50
- {
51
- queue: resourceName(options.name, 'jobs'),
52
- max_batch_size: 10,
53
- max_retries: 3,
54
- dead_letter_queue: resourceName(options.name, 'jobs-dlq'),
55
- },
56
- ],
57
- },
58
- }, `export default {
59
- async queue(batch: MessageBatch<unknown>): Promise<void> {
60
- for (const message of batch.messages) {
61
- // Add transactional idempotency and product processing before acknowledging.
62
- console.error('Job handler requires product implementation', message.id);
63
- message.retry({ delaySeconds: 60 });
64
- }
65
- },
66
- };
67
- `);
68
- }
69
- export function scaffoldCron({ root, options }) {
70
- worker(root, 'scheduled', {
71
- ...workerConfig(resourceName(options.name, 'scheduled')),
72
- triggers: { crons: ['0 * * * *'] },
73
- }, `export default {
74
- async scheduled(controller: ScheduledController): Promise<void> {
75
- // Define a product schedule, idempotency key, overlap policy, and failure alerts before release.
76
- console.log('Scheduled trigger', controller.scheduledTime);
77
- },
78
- };
79
- `);
80
- }
81
- export function scaffoldWorkflows({ root, options }) {
82
- worker(root, 'workflows', {
83
- ...workerConfig(resourceName(options.name, 'workflows')),
84
- workflows: [
85
- {
86
- name: resourceName(options.name, 'workflow'),
87
- binding: 'WORKFLOW',
88
- class_name: 'ApplicationWorkflow',
89
- },
90
- ],
91
- }, `import { WorkflowEntrypoint, type WorkflowEvent, type WorkflowStep } from 'cloudflare:workers';
92
- export class ApplicationWorkflow extends WorkflowEntrypoint<Env, { operationId: string }> {
93
- async run(event: WorkflowEvent<{ operationId: string }>, step: WorkflowStep) {
94
- return step.do('validate', { retries: { limit: 3, delay: '10 seconds', backoff: 'exponential' } }, async () => {
95
- if (typeof event.payload.operationId !== 'string' || !event.payload.operationId) {
96
- throw new Error('operationId required');
97
- }
98
- return { operationId: event.payload.operationId };
99
- });
100
- }
101
- }
102
- export default {
103
- async fetch() {
104
- return new Response('Use an authorized server binding to create workflows', { status: 403 });
105
- },
106
- };
107
- `);
108
- }
@@ -1,2 +0,0 @@
1
- import type { RecipeContext } from '../registry/types.js';
2
- export declare function scaffoldStream({ root, options, runtimeApp }: RecipeContext): void;