anhedral 0.12.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -39
- package/dist/capabilities.d.ts +3 -3
- package/dist/capability-contract.js +12 -1
- package/dist/command-schema.js +8 -2
- package/dist/command.js +9 -11
- package/dist/delivery.js +3 -1
- package/dist/dependencies.d.ts +6 -1
- package/dist/dependencies.js +13 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/platforms/mobile.d.ts +1 -1
- package/dist/platforms/mobile.js +44 -3
- package/dist/project-state.js +4 -1
- package/dist/provider-auth.js +6 -0
- package/dist/providers/adapters.js +9 -3
- package/dist/providers/runtime.js +11 -0
- package/dist/readiness.js +4 -2
- package/dist/registry/add.js +40 -7
- package/dist/registry/options.js +12 -0
- package/dist/registry/presets.d.ts +4 -0
- package/dist/registry/presets.js +41 -0
- package/dist/registry/resolve.d.ts +3 -1
- package/dist/registry/resolve.js +40 -14
- package/dist/registry/types.d.ts +1 -0
- package/dist/registry/usage.js +1 -1
- package/dist/runtime-policy.js +4 -1
- package/dist/scaffold/api.js +10 -2
- package/dist/scaffold/auth.d.ts +1 -1
- package/dist/scaffold/auth.js +22 -6
- package/dist/scaffold/backend.d.ts +6 -0
- package/dist/scaffold/backend.js +224 -0
- package/dist/scaffold/billing-config.d.ts +1 -0
- package/dist/scaffold/billing-config.js +73 -0
- package/dist/scaffold/billing-contracts.d.ts +2 -0
- package/dist/scaffold/billing-contracts.js +48 -0
- package/dist/scaffold/billing-providers.d.ts +1 -0
- package/dist/scaffold/billing-providers.js +249 -0
- package/dist/scaffold/billing-schema.d.ts +1 -0
- package/dist/scaffold/billing-schema.js +34 -0
- package/dist/scaffold/billing-security.d.ts +1 -0
- package/dist/scaffold/billing-security.js +46 -0
- package/dist/scaffold/billing-server.d.ts +1 -0
- package/dist/scaffold/billing-server.js +139 -0
- package/dist/scaffold/billing-store.d.ts +1 -0
- package/dist/scaffold/billing-store.js +72 -0
- package/dist/scaffold/billing.d.ts +2 -0
- package/dist/scaffold/billing.js +216 -0
- package/dist/scaffold/cloudflare-services.d.ts +8 -0
- package/dist/scaffold/cloudflare-services.js +198 -0
- package/dist/scaffold/compose.js +2 -0
- package/dist/scaffold/database.js +19 -2
- package/dist/scaffold/documentation.js +10 -6
- package/dist/scaffold/expo-auth.d.ts +3 -0
- package/dist/scaffold/expo-auth.js +192 -0
- package/dist/scaffold/expo-billing.d.ts +3 -0
- package/dist/scaffold/expo-billing.js +292 -0
- package/dist/scaffold/expo-runtime.d.ts +3 -0
- package/dist/scaffold/expo-runtime.js +134 -0
- package/dist/scaffold/integrations.d.ts +2 -1
- package/dist/scaffold/integrations.js +7 -2
- package/dist/scaffold/void.js +13 -5
- package/dist/scaffold/web.js +2 -0
- package/dist/scaffold/workspace.js +6 -1
- package/dist/ship.js +3 -1
- package/dist/stack-registry.d.ts +11 -2
- package/dist/stack-registry.js +136 -16
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/anhedral-stack.md +122 -0
- package/docs/software-factory.md +67 -8
- package/docs/stack-standard.md +126 -57
- package/docs/verification.md +113 -0
- package/package.json +7 -4
package/dist/readiness.js
CHANGED
|
@@ -46,7 +46,9 @@ export function inspectProject(root) {
|
|
|
46
46
|
record('selection', standard.schemaVersion === 1 &&
|
|
47
47
|
JSON.stringify(standard.products) === JSON.stringify(plan.products) &&
|
|
48
48
|
standard.hosting ===
|
|
49
|
-
(plan.products.includes('next') ||
|
|
49
|
+
(plan.products.includes('next') ||
|
|
50
|
+
plan.products.includes('vinext') ||
|
|
51
|
+
plan.products.includes('expo')
|
|
50
52
|
? plan.hosting
|
|
51
53
|
: null), 'Setup plan matches project selection');
|
|
52
54
|
}
|
|
@@ -80,7 +82,7 @@ export function validateSetupPlan(plan) {
|
|
|
80
82
|
throw new Error('Invalid hosting.');
|
|
81
83
|
validateRequirements(value.setup, value.products);
|
|
82
84
|
const selected = new Set(value.products);
|
|
83
|
-
resolveStandardProducts(selected, value.hosting, false);
|
|
85
|
+
resolveStandardProducts(selected, value.hosting, false, false);
|
|
84
86
|
if (selected.size !== value.products.length)
|
|
85
87
|
throw new Error('Invalid or incomplete setup selection.');
|
|
86
88
|
if (value.name !== undefined && typeof value.name !== 'string')
|
package/dist/registry/add.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { scaffoldCloudflareServiceContext } from '../scaffold/cloudflare-services.js';
|
|
1
2
|
import { PROJECT_CONFIG_FILE, readProjectSection, writeProjectSection, hasProjectSection, } from '../project-config.js';
|
|
3
|
+
import { scaffoldExpoRuntime } from '../scaffold/expo-runtime.js';
|
|
4
|
+
import { scaffoldWebBackend } from '../scaffold/backend.js';
|
|
2
5
|
import { configureDependencyPatches } from '../dependency-patches.js';
|
|
3
6
|
import { readBoundedFile, MAX_PROJECT_JSON_BYTES } from '../bounded-file.js';
|
|
4
7
|
import { bootstrapWorkspace, assertWorkspaceRuntime } from '../scaffold/bootstrap.js';
|
|
@@ -8,7 +11,7 @@ import { existsSync, lstatSync, readFileSync, realpathSync, rmSync } from 'node:
|
|
|
8
11
|
import path from 'node:path';
|
|
9
12
|
import { isDeepStrictEqual } from 'node:util';
|
|
10
13
|
import { applyEdits, modify, parse } from 'jsonc-parser';
|
|
11
|
-
import { STANDARD_PRODUCTS, installStackItem } from '../stack-registry.js';
|
|
14
|
+
import { STANDARD_PRODUCTS, getStackDefinition, installStackItem } from '../stack-registry.js';
|
|
12
15
|
import { inspectProject, validateSetupPlan } from '../readiness.js';
|
|
13
16
|
import { GENERATOR_VERSION } from '../version.js';
|
|
14
17
|
import { runStagedTransaction } from '../transaction.js';
|
|
@@ -19,7 +22,7 @@ import { put } from '../scaffold/files.js';
|
|
|
19
22
|
import { writeStandardRoot } from '../scaffold/workspace.js';
|
|
20
23
|
import { configureVoidDelivery, refreshVoidEnvironment } from '../scaffold/void.js';
|
|
21
24
|
import { createRecipeContext } from './context.js';
|
|
22
|
-
import { resolveStackRegistry, resolveStandardProducts } from './resolve.js';
|
|
25
|
+
import { resolveBillingProducts, resolveStackRegistry, resolveStandardProducts, } from './resolve.js';
|
|
23
26
|
import { sourceFiles, configurationFingerprints } from './receipt.js';
|
|
24
27
|
import { sourcePreview, validatePreviewPath, MAX_PREVIEW_TOTAL_BYTES, } from './preview.js';
|
|
25
28
|
/** Add recipes to an initialized workspace, refusing edits to customer-owned source. */
|
|
@@ -41,6 +44,9 @@ export async function addStackItems(root, request, run = execFile) {
|
|
|
41
44
|
if (!request.items.length)
|
|
42
45
|
throw new Error('Select at least one registry item.');
|
|
43
46
|
const plan = readProjectSection(root, 'setup');
|
|
47
|
+
if (Array.isArray(plan?.registry?.items) &&
|
|
48
|
+
plan.registry.items.some((item) => item.name === 'stripe' && item.package))
|
|
49
|
+
throw new Error('This project uses the legacy billing SDK recipe. Use its pinned CLI or perform a reviewed billing migration before adding capabilities.');
|
|
44
50
|
validateSetupPlan(plan);
|
|
45
51
|
if (plan.cliVersion !== GENERATOR_VERSION)
|
|
46
52
|
throw new Error('Use the project CLI version before adding recipes.');
|
|
@@ -61,11 +67,17 @@ export async function addStackItems(root, request, run = execFile) {
|
|
|
61
67
|
throw new Error(`Unknown stack product: ${id}.`);
|
|
62
68
|
selected.add(id);
|
|
63
69
|
}
|
|
64
|
-
|
|
70
|
+
const existingServerFeatures = plan.products.some((id) => Boolean(getStackDefinition(id).runtime));
|
|
71
|
+
if (!existingServerFeatures &&
|
|
72
|
+
request.items.some((id) => Boolean(getStackDefinition(id).runtime)))
|
|
73
|
+
selected.add('hono');
|
|
74
|
+
if (request.items.some((id) => ['stripe', 'revenuecat'].includes(id) && !plan.products.includes(id)))
|
|
75
|
+
resolveBillingProducts(selected);
|
|
76
|
+
if (['queues', 'basin', 'expo', 'images', 'analytics-engine'].some((id) => selected.has(id)) &&
|
|
65
77
|
hasProjectSection(root, 'cloudflare') &&
|
|
66
78
|
readProjectSection(root, 'cloudflare').deliveryEngine === 'void')
|
|
67
|
-
throw new Error('Queues
|
|
68
|
-
resolveStandardProducts(selected, plan.hosting, false);
|
|
79
|
+
throw new Error('Expo web, Queues, Basin, Images and Analytics Engine require Wrangler delivery. They cannot be added to a Void project.');
|
|
80
|
+
resolveStandardProducts(selected, plan.hosting, false, false);
|
|
69
81
|
const voidSelected = usesVoidSelection([...selected], plan.hosting);
|
|
70
82
|
if (!request.dryRun &&
|
|
71
83
|
voidSelected &&
|
|
@@ -82,6 +94,13 @@ export async function addStackItems(root, request, run = execFile) {
|
|
|
82
94
|
json: true,
|
|
83
95
|
initializeGit: false,
|
|
84
96
|
};
|
|
97
|
+
if (plan.products.includes('hono') &&
|
|
98
|
+
!existsSync(path.join(root, 'packages/contracts/package.json')) &&
|
|
99
|
+
(request.items.some((id) => ['vinext', 'next'].includes(id) && !plan.products.some((existing) => existing === id)) ||
|
|
100
|
+
(request.items.includes('better-auth') &&
|
|
101
|
+
!plan.products.includes('better-auth') &&
|
|
102
|
+
plan.products.some((id) => ['vinext', 'next'].includes(id)))))
|
|
103
|
+
throw new Error('This API predates shared contracts. Migrate its contracts and API endpoints explicitly before adding web/auth wiring.');
|
|
85
104
|
const registry = resolveStackRegistry(options);
|
|
86
105
|
const oldItems = new Map(plan.registry.items.map((item) => [item.name, item]));
|
|
87
106
|
const recipes = registry.items.filter((item) => item.installer === 'recipe' && !isDeepStrictEqual(oldItems.get(item.name), item));
|
|
@@ -124,13 +143,26 @@ export async function addStackItems(root, request, run = execFile) {
|
|
|
124
143
|
seedPaths: [...before.keys(), PROJECT_CONFIG_FILE],
|
|
125
144
|
build: async (stage) => {
|
|
126
145
|
const context = createRecipeContext(stage, options);
|
|
146
|
+
context.updating = true;
|
|
127
147
|
for (const item of registry.items)
|
|
128
148
|
Object.assign(context.bindings, item.bindings);
|
|
129
149
|
if (recipes.some((item) => ['vinext', 'next'].includes(item.name)) &&
|
|
130
150
|
!existsSync(path.join(stage, 'apps/web/package.json')))
|
|
131
151
|
bootstrapWorkspace(stage, options.name, run, true);
|
|
132
|
-
for (const item of recipes)
|
|
133
|
-
|
|
152
|
+
for (const item of recipes) {
|
|
153
|
+
if (item.name === 'expo' && plan.products.includes('expo')) {
|
|
154
|
+
scaffoldExpoRuntime(context);
|
|
155
|
+
}
|
|
156
|
+
else
|
|
157
|
+
await installStackItem(item, context);
|
|
158
|
+
}
|
|
159
|
+
// Connect a newly introduced backend without regenerating customer UI.
|
|
160
|
+
if (!plan.products.includes('hono') && selected.has('hono')) {
|
|
161
|
+
if (plan.products.includes('expo'))
|
|
162
|
+
scaffoldExpoRuntime(context);
|
|
163
|
+
if (plan.products.includes('next') || plan.products.includes('vinext'))
|
|
164
|
+
scaffoldWebBackend(context);
|
|
165
|
+
}
|
|
134
166
|
// Configuration items affect the existing runtime without regenerating its application source.
|
|
135
167
|
const configurationItems = registry.items.filter((item) => !isDeepStrictEqual(oldItems.get(item.name), item) && item.bindings);
|
|
136
168
|
if (configurationItems.length) {
|
|
@@ -148,6 +180,7 @@ export async function addStackItems(root, request, run = execFile) {
|
|
|
148
180
|
}
|
|
149
181
|
put(stage, file, content);
|
|
150
182
|
}
|
|
183
|
+
scaffoldCloudflareServiceContext(context);
|
|
151
184
|
writeStandardRoot(stage, options, registry, true);
|
|
152
185
|
if (voidSelected) {
|
|
153
186
|
configureVoidDelivery(stage);
|
package/dist/registry/options.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { applyPreset } from './presets.js';
|
|
1
2
|
import { resolveStandardProducts } from './resolve.js';
|
|
2
3
|
import path from 'node:path';
|
|
3
4
|
import { packageNameFromText } from '../render.js';
|
|
@@ -20,6 +21,7 @@ function parseStandardFlags(remaining) {
|
|
|
20
21
|
let hosting = 'cloudflare';
|
|
21
22
|
let hostingSpecified = false;
|
|
22
23
|
let gitSpecified;
|
|
24
|
+
let preset;
|
|
23
25
|
for (let index = 0; index < remaining.length; index++) {
|
|
24
26
|
const token = remaining[index];
|
|
25
27
|
if (['--skip-install', '--dry-run', '--json', '--verbose'].includes(token))
|
|
@@ -28,6 +30,14 @@ function parseStandardFlags(remaining) {
|
|
|
28
30
|
gitSpecified = readGitFlag(token, gitSpecified);
|
|
29
31
|
continue;
|
|
30
32
|
}
|
|
33
|
+
if (token === '--preset' || token.startsWith('--preset=')) {
|
|
34
|
+
if (preset !== undefined)
|
|
35
|
+
throw new Error('Specify --preset once.');
|
|
36
|
+
preset = token === '--preset' ? remaining[++index] : token.slice('--preset='.length);
|
|
37
|
+
if (!preset || preset.startsWith('-'))
|
|
38
|
+
throw new Error('Supply a value for --preset.');
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
31
41
|
if (token === '--hosting' || token.startsWith('--hosting=')) {
|
|
32
42
|
const value = token === '--hosting' ? remaining[++index] : token.slice('--hosting='.length);
|
|
33
43
|
hosting = readHostingFlag(value, hosting, hostingSpecified);
|
|
@@ -40,6 +50,8 @@ function parseStandardFlags(remaining) {
|
|
|
40
50
|
}
|
|
41
51
|
products.add(value);
|
|
42
52
|
}
|
|
53
|
+
if (preset)
|
|
54
|
+
applyPreset(preset, products);
|
|
43
55
|
if (!hostingSpecified && products.has('next'))
|
|
44
56
|
hosting = 'vercel';
|
|
45
57
|
return { products, hosting, hostingSpecified, gitSpecified };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { StandardProduct } from './types.js';
|
|
2
|
+
/** A compatible product selection, not mutually exclusive catalog alternatives. */
|
|
3
|
+
export declare const FULL_PRODUCT: readonly StandardProduct[];
|
|
4
|
+
export declare function applyPreset(name: string, selected: Set<StandardProduct>): void;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/** A compatible product selection, not mutually exclusive catalog alternatives. */
|
|
2
|
+
export const FULL_PRODUCT = Object.freeze([
|
|
3
|
+
'expo',
|
|
4
|
+
'hono',
|
|
5
|
+
'wxt',
|
|
6
|
+
'd1',
|
|
7
|
+
'better-auth',
|
|
8
|
+
'r2',
|
|
9
|
+
'kv',
|
|
10
|
+
'stripe',
|
|
11
|
+
'revenuecat',
|
|
12
|
+
'workers-ai',
|
|
13
|
+
'analytics-engine',
|
|
14
|
+
'basin',
|
|
15
|
+
'realtime',
|
|
16
|
+
'realtimekit',
|
|
17
|
+
'images',
|
|
18
|
+
'stream',
|
|
19
|
+
'video',
|
|
20
|
+
'queues',
|
|
21
|
+
'cron',
|
|
22
|
+
'workflows',
|
|
23
|
+
'resend',
|
|
24
|
+
'sentry',
|
|
25
|
+
]);
|
|
26
|
+
export function applyPreset(name, selected) {
|
|
27
|
+
if (!['minimal', 'full-product'].includes(name))
|
|
28
|
+
throw new Error('preset must be minimal or full-product.');
|
|
29
|
+
if (name === 'minimal')
|
|
30
|
+
return;
|
|
31
|
+
// Explicit provider/frontend choices replace the preset's corresponding default.
|
|
32
|
+
for (const id of FULL_PRODUCT) {
|
|
33
|
+
if (id === 'expo' && (selected.has('next') || selected.has('vinext')))
|
|
34
|
+
continue;
|
|
35
|
+
if (id === 'd1' && (selected.has('neon') || selected.has('neon-realtime')))
|
|
36
|
+
continue;
|
|
37
|
+
if (id === 'better-auth' && selected.has('clerk'))
|
|
38
|
+
continue;
|
|
39
|
+
selected.add(id);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { Hosting, StandardOptions, StandardProduct, StackRegistryItem } from './types.js';
|
|
2
|
+
/** Explicit billing selection needs an authenticated server and durable state. */
|
|
3
|
+
export declare function resolveBillingProducts(selected: Set<StandardProduct>): void;
|
|
2
4
|
/** Apply default selections once. All callers then use the same strict graph resolver. */
|
|
3
|
-
export declare function resolveStandardProducts(selected: Set<StandardProduct>, hosting: Hosting, hostingSpecified: boolean): void;
|
|
5
|
+
export declare function resolveStandardProducts(selected: Set<StandardProduct>, hosting: Hosting, hostingSpecified: boolean, initializing?: boolean): void;
|
|
4
6
|
export interface ResolvedStackRegistry {
|
|
5
7
|
schemaVersion: number;
|
|
6
8
|
name: string;
|
package/dist/registry/resolve.js
CHANGED
|
@@ -9,6 +9,14 @@ function needsWorker(name, context) {
|
|
|
9
9
|
return (definition.runtime === 'worker' ||
|
|
10
10
|
(definition.runtime === 'optional-worker' && hasServer(context)));
|
|
11
11
|
}
|
|
12
|
+
/** Explicit billing selection needs an authenticated server and durable state. */
|
|
13
|
+
export function resolveBillingProducts(selected) {
|
|
14
|
+
selected.add('hono');
|
|
15
|
+
if (!selected.has('clerk'))
|
|
16
|
+
selected.add('better-auth');
|
|
17
|
+
if (!selected.has('neon') && !selected.has('d1'))
|
|
18
|
+
selected.add(selected.has('neon-realtime') ? 'neon' : 'd1');
|
|
19
|
+
}
|
|
12
20
|
function validateProducts(selected, hosting) {
|
|
13
21
|
if (!['cloudflare', 'vercel'].includes(hosting))
|
|
14
22
|
throw new Error('hosting must be cloudflare or vercel.');
|
|
@@ -29,28 +37,46 @@ function validateProducts(selected, hosting) {
|
|
|
29
37
|
throw new Error('Vinext requires Cloudflare hosting; select --next for Vercel.');
|
|
30
38
|
}
|
|
31
39
|
/** Apply default selections once. All callers then use the same strict graph resolver. */
|
|
32
|
-
export function resolveStandardProducts(selected, hosting, hostingSpecified) {
|
|
40
|
+
export function resolveStandardProducts(selected, hosting, hostingSpecified, initializing = true) {
|
|
33
41
|
for (const id of selected)
|
|
34
42
|
getStackDefinition(id);
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const
|
|
44
|
-
if (
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
const applications = [...selected].filter((id) => getStackDefinition(id).type === 'application');
|
|
44
|
+
if (!applications.length)
|
|
45
|
+
selected.add(hosting === 'vercel' ? 'next' : 'expo');
|
|
46
|
+
// Resolve to a fixed point: an addition may introduce another dependency.
|
|
47
|
+
// Readiness/add callers preserve an existing web-owned backend; new profiles
|
|
48
|
+
// use Hono whenever privileged server behavior is selected.
|
|
49
|
+
let changed = true;
|
|
50
|
+
while (changed) {
|
|
51
|
+
const before = selected.size;
|
|
52
|
+
if (selected.has('stripe') || selected.has('revenuecat'))
|
|
53
|
+
resolveBillingProducts(selected);
|
|
54
|
+
const defaults = [...selected].sort((left, right) => (getStackDefinition(left).selection.requiresAny?.length ?? 0) -
|
|
55
|
+
(getStackDefinition(right).selection.requiresAny?.length ?? 0) ||
|
|
56
|
+
left.localeCompare(right));
|
|
57
|
+
for (const id of defaults) {
|
|
58
|
+
const definition = getStackDefinition(id);
|
|
59
|
+
const alternatives = definition.selection.requiresAny ?? [];
|
|
60
|
+
if (definition.fallbackDependency &&
|
|
61
|
+
!alternatives.some((other) => selected.has(other)))
|
|
62
|
+
selected.add(definition.fallbackDependency);
|
|
63
|
+
for (const dependency of definition.selection.requiresAll ?? [])
|
|
64
|
+
selected.add(dependency);
|
|
65
|
+
const serverCapability = Boolean(definition.runtime);
|
|
66
|
+
if (serverCapability &&
|
|
67
|
+
(initializing || !hasServer(createResolutionContext({ products: [...selected], hosting }))))
|
|
68
|
+
selected.add('hono');
|
|
69
|
+
}
|
|
70
|
+
changed = selected.size !== before;
|
|
47
71
|
}
|
|
48
72
|
const context = createResolutionContext({ products: [...selected], hosting });
|
|
49
73
|
if (context.has('next') &&
|
|
50
74
|
hosting === 'vercel' &&
|
|
51
75
|
[...selected].some((id) => needsWorker(id, context)))
|
|
52
76
|
selected.add('hono');
|
|
53
|
-
if (
|
|
77
|
+
if (selected.has('expo') && hosting === 'vercel' && !selected.has('next'))
|
|
78
|
+
throw new Error('Expo web uses Cloudflare hosting; select --next for a Vercel web application.');
|
|
79
|
+
if (hostingSpecified && !selected.has('next') && !selected.has('vinext') && !selected.has('expo'))
|
|
54
80
|
throw new Error('--hosting applies to the web application.');
|
|
55
81
|
resolveStackRegistry({ products: [...selected], hosting });
|
|
56
82
|
}
|
package/dist/registry/types.d.ts
CHANGED
package/dist/registry/usage.js
CHANGED
|
@@ -15,4 +15,4 @@ export function commandHelp(command) {
|
|
|
15
15
|
export const STANDARD_USAGE = `Anhedral\nScaffold source, authenticate your providers, and ship your selected stack.\n\nUsage: anhedral <command> [options]\n\nStart here:\n${primary.map((name) => ` ${name.padEnd(12)}${COMMAND_HELP[name].description}`).join('\n')}\n\nDelivery tools:\n${Object.entries(COMMAND_HELP)
|
|
16
16
|
.filter(([name]) => !primary.includes(name))
|
|
17
17
|
.map(([name, entry]) => ` ${name.padEnd(12)}${entry.description}`)
|
|
18
|
-
.join('\n')}\n\nDefault:
|
|
18
|
+
.join('\n')}\n\nDefault: minimal Expo web, iOS and Android app in a pnpm/Turborepo workspace. Add API, identity, data and services when needed; --preset full-product selects the complete compatible stack.\nExamples:\n anhedral init client-app\n anhedral auth client-app\n anhedral ship client-app --dry-run\n\nUse anhedral <command> --help for options and examples.\nUse anhedral help <command> for the same focused help.\nGlobal options:\n${common.map((option) => ` ${option}`).join('\n')}\n -v, --version Show the CLI version.\n`;
|
package/dist/runtime-policy.js
CHANGED
|
@@ -14,8 +14,11 @@ export function supportsVoidRuntime(version) {
|
|
|
14
14
|
return major > 24 || (major === 24 && minor >= 21);
|
|
15
15
|
}
|
|
16
16
|
export function usesVoidSelection(products, hosting) {
|
|
17
|
-
return (!
|
|
17
|
+
return (!products.includes('expo') &&
|
|
18
|
+
!(products.includes('next') && hosting === 'cloudflare') &&
|
|
18
19
|
!products.includes('queues') &&
|
|
19
20
|
!products.includes('basin') &&
|
|
21
|
+
!products.includes('images') &&
|
|
22
|
+
!products.includes('analytics-engine') &&
|
|
20
23
|
products.some((product) => ['vinext', 'hono', 'realtime', 'cron', 'workflows'].includes(product)));
|
|
21
24
|
}
|
package/dist/scaffold/api.js
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
+
import { scaffoldContracts } from './backend.js';
|
|
1
2
|
import { resourceName, jsString } from '../render.js';
|
|
2
3
|
import { STACK_DEPENDENCIES } from '../dependencies.js';
|
|
3
4
|
import { workerConfig, worker } from './files.js';
|
|
4
5
|
export function scaffoldApi({ root, options, bindings }) {
|
|
5
|
-
|
|
6
|
+
scaffoldContracts(root);
|
|
7
|
+
worker(root, 'api', { ...workerConfig(resourceName(options.name, 'api')), ...bindings }, `import { OpenAPIHono, createRoute } from '@hono/zod-openapi';
|
|
8
|
+
|
|
9
|
+
import { healthSchema } from '@workspace/contracts';
|
|
10
|
+
import { bodyLimit } from 'hono/body-limit';
|
|
6
11
|
|
|
7
12
|
const app = new OpenAPIHono<{ Bindings: Env }>();
|
|
13
|
+
app.use('/api/*', bodyLimit({ maxSize: 1024 * 1024 }));
|
|
8
14
|
const health = createRoute({
|
|
9
15
|
method: 'get',
|
|
10
16
|
path: '/health',
|
|
11
17
|
responses: {
|
|
12
18
|
200: {
|
|
13
19
|
description: 'Healthy',
|
|
14
|
-
content: { 'application/json': { schema:
|
|
20
|
+
content: { 'application/json': { schema: healthSchema } },
|
|
15
21
|
},
|
|
16
22
|
},
|
|
17
23
|
});
|
|
18
24
|
|
|
19
25
|
app.openapi(health, (c) => c.json({ ok: true as const }, 200));
|
|
26
|
+
app.get('/api/health', (c) => c.json(healthSchema.parse({ ok: true })));
|
|
20
27
|
app.doc('/openapi.json', {
|
|
21
28
|
openapi: '3.0.0',
|
|
22
29
|
info: { title: ${jsString(options.name)}, version: '1.0.0' },
|
|
@@ -24,6 +31,7 @@ app.doc('/openapi.json', {
|
|
|
24
31
|
|
|
25
32
|
export default app;
|
|
26
33
|
`, {
|
|
34
|
+
'@workspace/contracts': 'workspace:*',
|
|
27
35
|
hono: STACK_DEPENDENCIES['hono'],
|
|
28
36
|
'@hono/zod-openapi': STACK_DEPENDENCIES['@hono/zod-openapi'],
|
|
29
37
|
});
|
package/dist/scaffold/auth.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { RecipeContext } from '../registry/types.js';
|
|
2
|
-
export declare function scaffoldBetterAuth({ root, options, runtimeApp, has }: RecipeContext): void;
|
|
2
|
+
export declare function scaffoldBetterAuth({ root, options, runtimeApp, has, updating, }: RecipeContext): void;
|
|
3
3
|
export declare function scaffoldClerk({ root, has }: RecipeContext): void;
|
package/dist/scaffold/auth.js
CHANGED
|
@@ -1,24 +1,31 @@
|
|
|
1
|
+
import { scaffoldContracts, scaffoldWebAuth } from './backend.js';
|
|
2
|
+
import { expoAuthScheme, scaffoldExpoAuth } from './expo-auth.js';
|
|
3
|
+
import { jsString } from '../render.js';
|
|
1
4
|
import { writeEnvironmentFile } from './environment.js';
|
|
2
5
|
import { STACK_DEPENDENCIES } from '../dependencies.js';
|
|
3
6
|
import { existsSync, readFileSync } from 'node:fs';
|
|
4
7
|
import path from 'node:path';
|
|
5
8
|
import { writeBetterAuthSchema } from '../auth-schema.js';
|
|
6
9
|
import { put, patchPackage, sharedPackage } from './files.js';
|
|
7
|
-
export function scaffoldBetterAuth({ root, options, runtimeApp, has }) {
|
|
10
|
+
export function scaffoldBetterAuth({ root, options, runtimeApp, has, updating, }) {
|
|
11
|
+
const scheme = has('expo') ? expoAuthScheme(root) : undefined;
|
|
8
12
|
writeBetterAuthSchema(root, has('neon'));
|
|
9
|
-
sharedPackage(root, 'auth',
|
|
13
|
+
sharedPackage(root, 'auth', `${scheme ? "import { expo } from '@better-auth/expo';\n" : ''}import { betterAuth } from 'better-auth';
|
|
10
14
|
import { drizzleAdapter } from '@better-auth/drizzle-adapter';
|
|
11
15
|
import type { createDatabase } from '@workspace/db';
|
|
12
|
-
export function createAuth(db: ReturnType<typeof createDatabase>, secret: string, baseURL: string) {
|
|
16
|
+
export function createAuth(db: ReturnType<typeof createDatabase>, secret: string, baseURL: string, trustedOrigins: string[] = [new URL(baseURL).origin${scheme ? `, ${jsString(scheme + '://')}` : ''}]) {
|
|
13
17
|
return betterAuth({
|
|
14
18
|
database: drizzleAdapter(db, { provider: '${has('neon') ? 'pg' : 'sqlite'}', transaction: false }),
|
|
15
19
|
secret,
|
|
16
20
|
baseURL,
|
|
21
|
+
trustedOrigins,
|
|
22
|
+
${scheme ? 'plugins: [expo()],' : ''}
|
|
17
23
|
emailAndPassword: { enabled: true },
|
|
18
24
|
});
|
|
19
25
|
}
|
|
20
26
|
`, {
|
|
21
27
|
'better-auth': STACK_DEPENDENCIES['better-auth'],
|
|
28
|
+
...(scheme ? { '@better-auth/expo': STACK_DEPENDENCIES['@better-auth/expo'] } : {}),
|
|
22
29
|
'@better-auth/drizzle-adapter': STACK_DEPENDENCIES['@better-auth/drizzle-adapter'],
|
|
23
30
|
'@workspace/db': 'workspace:*',
|
|
24
31
|
});
|
|
@@ -27,9 +34,14 @@ export function createAuth(db: ReturnType<typeof createDatabase>, secret: string
|
|
|
27
34
|
});
|
|
28
35
|
const connection = has('neon') ? 'createDatabase(env.DATABASE_URL)' : 'createDatabase(env.DB)';
|
|
29
36
|
if (has('hono')) {
|
|
37
|
+
if (!existsSync(path.join(root, 'packages/contracts/package.json')))
|
|
38
|
+
scaffoldContracts(root);
|
|
39
|
+
patchPackage(root, 'apps/api/package.json', {
|
|
40
|
+
dependencies: { '@workspace/contracts': 'workspace:*' },
|
|
41
|
+
});
|
|
30
42
|
const source = readFileSync(path.join(root, 'apps/api/src/index.ts'), 'utf8');
|
|
31
|
-
put(root, 'apps/api/src/index.ts', `import { createAuth } from '@workspace/auth';\
|
|
32
|
-
source.replace('export default app;', `app.on(['GET', 'POST'], '/api/auth/*', async (c) => {\n const env = c.env;\n const database = ${connection};\n return await createAuth(database, env.BETTER_AUTH_SECRET, env.BETTER_AUTH_URL).handler(c.req.raw);\n});\nexport default app;`));
|
|
43
|
+
put(root, 'apps/api/src/index.ts', `import { createAuth } from '@workspace/auth';\n${source.includes("import { createDatabase } from '@workspace/db'") ? '' : "import { createDatabase } from '@workspace/db';\n"}import { sessionSchema } from '@workspace/contracts';\n` +
|
|
44
|
+
source.replace('export default app;', `app.get('/api/session', async (c) => {\n const env = c.env;\n const session = await createAuth(${connection}, env.BETTER_AUTH_SECRET, env.BETTER_AUTH_URL).api.getSession({ headers: c.req.raw.headers });\n c.header('cache-control', 'private, no-store');\n if (!session) return c.json({ error: 'Unauthorized' }, 401);\n return c.json(sessionSchema.parse({ user: session.user }));\n});\napp.on(['GET', 'POST'], '/api/auth/*', async (c) => {\n const env = c.env;\n const database = ${connection};\n return await createAuth(database, env.BETTER_AUTH_SECRET, env.BETTER_AUTH_URL).handler(c.req.raw);\n});\nexport default app;`));
|
|
33
45
|
}
|
|
34
46
|
else {
|
|
35
47
|
put(root, 'apps/web/app/api/auth/[...all]/route.ts', `${has('vinext') ? "import { env } from 'cloudflare:workers';" : options.hosting === 'cloudflare' ? "import { getCloudflareContext } from '@opennextjs/cloudflare';" : ''}
|
|
@@ -54,8 +66,12 @@ export { handler as GET, handler as POST };
|
|
|
54
66
|
writeEnvironmentFile(root, `apps/${runtimeApp}/${runtimeApp === 'web' && options.hosting === 'vercel' ? '.env.example' : '.dev.vars.example'}`, {
|
|
55
67
|
...(has('neon') ? { DATABASE_URL: '' } : {}),
|
|
56
68
|
BETTER_AUTH_SECRET: '',
|
|
57
|
-
BETTER_AUTH_URL: `http://localhost:${
|
|
69
|
+
BETTER_AUTH_URL: `http://localhost:${has('vinext') || has('next') || has('expo') ? '3000' : '8787'}`,
|
|
58
70
|
});
|
|
71
|
+
if (has('hono') && (has('vinext') || has('next')))
|
|
72
|
+
scaffoldWebAuth(root);
|
|
73
|
+
if (scheme)
|
|
74
|
+
scaffoldExpoAuth(root, scheme, !updating);
|
|
59
75
|
if (has('hono'))
|
|
60
76
|
put(root, 'apps/api/src/secrets.d.ts', 'interface Env { BETTER_AUTH_SECRET: string; BETTER_AUTH_URL: string }\n');
|
|
61
77
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { RecipeContext } from '../registry/types.js';
|
|
2
|
+
/** Public contracts never import a framework, database or auth server. */
|
|
3
|
+
export declare function scaffoldContracts(root: string): void;
|
|
4
|
+
/** A single trusted upstream; never forward provider/edge identity headers from browsers. */
|
|
5
|
+
export declare function scaffoldWebBackend({ root, options, has }: RecipeContext): void;
|
|
6
|
+
export declare function scaffoldWebAuth(root: string): void;
|