anhedral 0.13.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.
- package/README.md +35 -232
- package/assets/patches/audit-deps.mjs +12 -2
- package/assets/ui/LICENSE.shadcn +21 -0
- package/assets/ui/UPSTREAM.json +33 -0
- package/assets/ui/native/button.tsx +85 -0
- package/assets/ui/native/card.tsx +33 -0
- package/assets/ui/native/dialog.tsx +75 -0
- package/assets/ui/native/input.tsx +27 -0
- package/assets/ui/native/label.tsx +4 -0
- package/assets/ui/native/layout.tsx +26 -0
- package/assets/ui/native/text.tsx +20 -0
- package/assets/ui/native/theme-switcher.tsx +22 -0
- package/assets/ui/theme-storage.ts +25 -0
- package/assets/ui/theme.tsx +66 -0
- package/assets/ui/web/button.tsx +59 -0
- package/assets/ui/web/input.tsx +21 -0
- package/assets/ui/web/label.tsx +19 -0
- package/dist/capabilities.d.ts +5 -5
- package/dist/capabilities.js +3 -21
- package/dist/capability-contract.d.ts +3 -3
- package/dist/capability-contract.js +11 -50
- package/dist/cli-delivery.d.ts +1 -1
- package/dist/cli-delivery.js +5 -65
- package/dist/cli-output.js +3 -3
- package/dist/command-schema.js +35 -86
- package/dist/delivery-evidence.d.ts +1 -1
- package/dist/delivery-evidence.js +7 -36
- package/dist/delivery.d.ts +2 -8
- package/dist/delivery.js +20 -101
- package/dist/dependencies.d.ts +6 -57
- package/dist/dependencies.js +54 -188
- package/dist/index.d.ts +1 -4
- package/dist/index.js +1 -4
- package/dist/inspector-model.d.ts +2 -2
- package/dist/integration-service-readers.d.ts +1 -2
- package/dist/integration-service-readers.js +3 -84
- package/dist/lifecycle-model.d.ts +1 -1
- package/dist/lifecycle-model.js +1 -1
- package/dist/mobile-delivery.d.ts +1 -1
- package/dist/mobile-delivery.js +4 -0
- package/dist/platforms/mobile.js +30 -121
- package/dist/platforms/web.d.ts +3 -0
- package/dist/platforms/web.js +299 -0
- package/dist/project-config.d.ts +1 -1
- package/dist/project-config.js +0 -1
- package/dist/project-inspector.js +5 -36
- package/dist/project-state.d.ts +1 -3
- package/dist/project-state.js +2 -85
- package/dist/provider-auth.js +3 -38
- package/dist/provider-readiness.d.ts +1 -1
- package/dist/provider-readiness.js +5 -24
- package/dist/providers/adapters.js +0 -175
- package/dist/providers/api.d.ts +1 -1
- package/dist/providers/api.js +3 -3
- package/dist/providers/config.js +2 -48
- package/dist/providers/definitions.d.ts +1 -204
- package/dist/providers/definitions.js +0 -85
- package/dist/providers/provision.d.ts +1 -1
- package/dist/providers/receipts.js +1 -11
- package/dist/providers/recovery-verification.js +1 -61
- package/dist/providers/runtime.js +4 -35
- package/dist/providers/state.js +1 -7
- package/dist/provision.d.ts +5 -13
- package/dist/provision.js +4 -80
- package/dist/readiness.d.ts +1 -1
- package/dist/readiness.js +3 -8
- package/dist/registry/add.js +10 -70
- package/dist/registry/bootstrap.d.ts +3 -2
- package/dist/registry/bootstrap.js +4 -13
- package/dist/registry/commands.js +8 -10
- package/dist/registry/context.js +0 -1
- package/dist/registry/options.js +8 -38
- package/dist/registry/resolve.d.ts +3 -4
- package/dist/registry/resolve.js +26 -108
- package/dist/registry/types.d.ts +1 -7
- package/dist/registry/usage.js +2 -2
- package/dist/runtime-policy.d.ts +0 -2
- package/dist/runtime-policy.js +0 -16
- package/dist/scaffold/auth.d.ts +1 -2
- package/dist/scaffold/auth.js +55 -130
- package/dist/scaffold/backend.d.ts +0 -4
- package/dist/scaffold/backend.js +1 -186
- package/dist/scaffold/billing-schema.d.ts +1 -1
- package/dist/scaffold/billing-schema.js +4 -4
- package/dist/scaffold/billing.js +11 -19
- package/dist/scaffold/bootstrap.d.ts +2 -3
- package/dist/scaffold/bootstrap.js +37 -43
- package/dist/scaffold/compose.js +2 -14
- package/dist/scaffold/database.d.ts +1 -1
- package/dist/scaffold/database.js +18 -126
- package/dist/scaffold/documentation.d.ts +0 -1
- package/dist/scaffold/documentation.js +22 -86
- package/dist/scaffold/expo-auth.js +33 -22
- package/dist/scaffold/expo-billing.js +17 -52
- package/dist/scaffold/expo-runtime.d.ts +2 -2
- package/dist/scaffold/expo-runtime.js +6 -97
- package/dist/scaffold/integrations.d.ts +1 -3
- package/dist/scaffold/integrations.js +9 -10
- package/dist/scaffold/managed-email.d.ts +3 -0
- package/dist/scaffold/managed-email.js +47 -0
- package/dist/scaffold/native-ui.d.ts +2 -0
- package/dist/scaffold/native-ui.js +69 -0
- package/dist/scaffold/password-reset.d.ts +1 -0
- package/dist/scaffold/password-reset.js +99 -0
- package/dist/scaffold/private-files.d.ts +2 -0
- package/dist/scaffold/private-files.js +78 -0
- package/dist/scaffold/stack-documentation.d.ts +0 -1
- package/dist/scaffold/stack-documentation.js +3 -49
- package/dist/scaffold/styling.d.ts +1 -1
- package/dist/scaffold/styling.js +20 -28
- package/dist/scaffold/web-billing.d.ts +2 -0
- package/dist/scaffold/web-billing.js +48 -0
- package/dist/scaffold/workspace.js +53 -194
- package/dist/service-deletion.js +1 -1
- package/dist/service-descriptor.js +5 -12
- package/dist/service-model.d.ts +1 -1
- package/dist/service-operations.js +2 -32
- package/dist/service-readers.js +1 -32
- package/dist/services-command.d.ts +1 -1
- package/dist/services-command.js +3 -9
- package/dist/ship.d.ts +3 -316
- package/dist/ship.js +10 -142
- package/dist/stack-registry.d.ts +2 -52
- package/dist/stack-registry.js +55 -403
- package/dist/standard.js +7 -14
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/anhedral-stack.md +23 -122
- package/docs/assets/anhedral-stack-light.png +0 -0
- package/docs/assets/anhedral-stack.png +0 -0
- package/docs/software-factory.md +24 -557
- package/docs/stack-standard.md +47 -294
- package/docs/verification.md +320 -0
- package/package.json +20 -22
- package/dist/neon-service-data.d.ts +0 -8
- package/dist/neon-service-data.js +0 -117
- package/dist/platforms/desktop.d.ts +0 -2
- package/dist/platforms/desktop.js +0 -415
- package/dist/platforms/extension.d.ts +0 -2
- package/dist/platforms/extension.js +0 -328
- package/dist/registry/presets.d.ts +0 -4
- package/dist/registry/presets.js +0 -41
- package/dist/scaffold/cloudflare-services.d.ts +0 -8
- package/dist/scaffold/cloudflare-services.js +0 -198
- package/dist/scaffold/lint.d.ts +0 -4
- package/dist/scaffold/lint.js +0 -56
- package/dist/scaffold/neon-realtime.d.ts +0 -2
- package/dist/scaffold/neon-realtime.js +0 -97
- package/dist/scaffold/services.d.ts +0 -5
- package/dist/scaffold/services.js +0 -108
- package/dist/scaffold/stream.d.ts +0 -2
- package/dist/scaffold/stream.js +0 -114
- package/dist/scaffold/void.d.ts +0 -4
- package/dist/scaffold/void.js +0 -264
- package/dist/scaffold/web.d.ts +0 -2
- package/dist/scaffold/web.js +0 -130
- package/dist/vercel-project.d.ts +0 -101
- package/dist/vercel-project.js +0 -305
- package/dist/vercel.d.ts +0 -67
- package/dist/vercel.js +0 -581
- package/dist/vinext.d.ts +0 -2
- package/dist/vinext.js +0 -86
- package/dist/void-execution.d.ts +0 -10
- package/dist/void-execution.js +0 -94
- package/dist/void-migrations.d.ts +0 -6
- package/dist/void-migrations.js +0 -110
- package/dist/void-state.d.ts +0 -16
- package/dist/void-state.js +0 -65
- package/dist/void.d.ts +0 -3
- package/dist/void.js +0 -5
|
@@ -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
|
-
}
|
package/dist/scaffold/stream.js
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { rmSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { patchPackage, put, sharedPackage } from './files.js';
|
|
4
|
-
import { writeEnvironmentFile } from './environment.js';
|
|
5
|
-
export function scaffoldStream({ root, options, runtimeApp }) {
|
|
6
|
-
sharedPackage(root, 'stream', '', {});
|
|
7
|
-
rmSync(path.join(root, 'packages/stream/src/index.ts'));
|
|
8
|
-
patchPackage(root, 'packages/stream/package.json', {
|
|
9
|
-
exports: { './server': './src/server.ts' },
|
|
10
|
-
});
|
|
11
|
-
put(root, 'packages/stream/src/server.ts', streamServer);
|
|
12
|
-
put(root, 'packages/stream/README.md', streamGuide);
|
|
13
|
-
const app = `apps/${runtimeApp}`;
|
|
14
|
-
const native = runtimeApp === 'web' && options.hosting === 'vercel';
|
|
15
|
-
writeEnvironmentFile(root, `${app}/${native ? '.env.example' : '.dev.vars.example'}`, {
|
|
16
|
-
STREAM_ACCOUNT_ID: '',
|
|
17
|
-
STREAM_API_TOKEN: '',
|
|
18
|
-
});
|
|
19
|
-
if (!native)
|
|
20
|
-
put(root, `${app}/${runtimeApp === 'api' ? 'src/' : ''}stream-secrets.d.ts`, runtimeApp === 'api'
|
|
21
|
-
? 'interface Env { STREAM_ACCOUNT_ID: string; STREAM_API_TOKEN: string }\n'
|
|
22
|
-
: 'declare namespace Cloudflare { interface Env { STREAM_ACCOUNT_ID: string; STREAM_API_TOKEN: string } }\n');
|
|
23
|
-
}
|
|
24
|
-
const streamServer = `// Server code only. Never serialize a live input directly to viewers: it contains a publish credential.
|
|
25
|
-
export interface StreamLiveInput {
|
|
26
|
-
uid: string;
|
|
27
|
-
webRTC: { url: string };
|
|
28
|
-
webRTCPlayback: { url: string };
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function readString(value: unknown): string {
|
|
32
|
-
if (typeof value !== 'string') throw new Error('Stream did not return a WebRTC live input.');
|
|
33
|
-
return value;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function readEndpoint(endpoint?: { url?: unknown } | null): { url: string } {
|
|
37
|
-
return { url: readString(endpoint?.url) };
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function readLiveInput(body: { success?: boolean; result?: Partial<StreamLiveInput> } | null): StreamLiveInput {
|
|
41
|
-
if (body?.success !== true) throw new Error('Stream live input request was unsuccessful.');
|
|
42
|
-
const input = body.result ?? {};
|
|
43
|
-
return { uid: readString(input.uid), webRTC: readEndpoint(input.webRTC), webRTCPlayback: readEndpoint(input.webRTCPlayback) };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function createStream(options: { accountId: string; apiToken: string }) {
|
|
47
|
-
if (!/^[a-f0-9]{32}$/i.test(options.accountId) || !options.apiToken.trim()) {
|
|
48
|
-
throw new Error('Configure server-only STREAM_ACCOUNT_ID and STREAM_API_TOKEN.');
|
|
49
|
-
}
|
|
50
|
-
const base = 'https://api.cloudflare.com/client/v4/accounts/' + options.accountId + '/stream/live_inputs';
|
|
51
|
-
async function request(url: string, init: RequestInit): Promise<StreamLiveInput> {
|
|
52
|
-
const response = await fetch(url, {
|
|
53
|
-
...init,
|
|
54
|
-
headers: { Authorization: 'Bearer ' + options.apiToken, 'Content-Type': 'application/json' },
|
|
55
|
-
redirect: 'error',
|
|
56
|
-
signal: AbortSignal.timeout(30_000),
|
|
57
|
-
});
|
|
58
|
-
// Do not include provider bodies or URLs in errors: they can contain broadcast credentials.
|
|
59
|
-
if (!response.ok) throw new Error('Stream live input request failed (HTTP ' + response.status + ').');
|
|
60
|
-
const body = await response.json().catch(() => {
|
|
61
|
-
throw new Error('Stream returned an invalid JSON response.');
|
|
62
|
-
}) as { success?: boolean; result?: Partial<StreamLiveInput> } | null;
|
|
63
|
-
return readLiveInput(body);
|
|
64
|
-
}
|
|
65
|
-
return {
|
|
66
|
-
// Call only after creator authorization and quota checks. Persist uid; do not create on every page load.
|
|
67
|
-
// Select playback privacy explicitly. Signed playback still needs application token issuance.
|
|
68
|
-
createLiveInput(input: { name: string; requireSignedURLs: boolean }) {
|
|
69
|
-
if (!input.name.trim() || typeof input.requireSignedURLs !== 'boolean') {
|
|
70
|
-
throw new Error('Supply a stream name and explicit signed-playback policy.');
|
|
71
|
-
}
|
|
72
|
-
return request(base, { method: 'POST', body: JSON.stringify({
|
|
73
|
-
meta: { name: input.name }, recording: { mode: 'off', requireSignedURLs: input.requireSignedURLs },
|
|
74
|
-
}) });
|
|
75
|
-
},
|
|
76
|
-
getLiveInput(uid: string) {
|
|
77
|
-
if (!/^[a-f0-9]{32}$/i.test(uid)) throw new Error('Invalid Stream live input ID.');
|
|
78
|
-
return request(base + '/' + uid, { method: 'GET' });
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
`;
|
|
83
|
-
const streamGuide = `# Cloudflare Stream Live WebRTC
|
|
84
|
-
|
|
85
|
-
Optional one-to-many live video using WHIP ingest and WHEP playback. GA since October 15, 2026. This is independent of --realtime Durable Object messaging and --neon-realtime live SQL. For many-to-many calls, review Cloudflare Realtime separately; this package does not scaffold conferencing.
|
|
86
|
-
|
|
87
|
-
## Server integration
|
|
88
|
-
|
|
89
|
-
Add @workspace/stream as a workspace:* dependency of the server app and import createStream from @workspace/stream/server. Pass { accountId: env.STREAM_ACCOUNT_ID, apiToken: env.STREAM_API_TOKEN }. The factory supports createLiveInput({ name, requireSignedURLs }) and getLiveInput(uid). It returns uid, webRTC.url (secret WHIP ingest) and webRTCPlayback.url (WHEP playback). No browser management client or public management route is generated.
|
|
90
|
-
|
|
91
|
-
Use a customer-owned account with Stream enabled and an account-scoped Stream Write API token. Configure the selected server app's ignored runtime file from its environment example (.env for Void, .dev.vars for Wrangler, .env.local for native Next.js). The root .env.example is an inventory. Configure production secrets explicitly with the selected host; anhedral ship does not activate Stream, create live inputs or install these runtime credentials automatically. There is no Wrangler resource binding for this integration. Never use a public environment prefix for the management token or publish URL.
|
|
92
|
-
|
|
93
|
-
Authorize creators and enforce quotas before creating/retrieving an input. Persist its uid with the owning user/tenant; authorize access before calling getLiveInput. Reuse the input on refresh; reconcile uncertain creates rather than blindly retrying. Return the WHIP URL only to its authorized broadcaster, with Cache-Control: no-store. Anyone possessing it can broadcast. Never return the full input to viewers or put it in logs, committed config, static assets or public build variables. Rotate compromised publish keys through Cloudflare's supported management workflow.
|
|
94
|
-
|
|
95
|
-
Select requireSignedURLs explicitly. For private viewing implement authenticated, short-lived Stream playback token issuance and verify WHEP rejects unsigned, expired and unauthorized access. Hosting protection alone does not protect Cloudflare's media endpoints. Origin restrictions are not user authorization. The helper does not issue playback tokens or establish private media acceptance.
|
|
96
|
-
|
|
97
|
-
## Browser integration
|
|
98
|
-
|
|
99
|
-
Use native RTCPeerConnection or a Cloudflare-supported WHIP/WHEP client. Follow the official browser tutorial below. Capture camera/microphone only after a user action over HTTPS or localhost; handle denied permissions, device selection and autoplay restrictions. Publish send-only tracks to the authorized WHIP URL; receive audio/video tracks through WHEP. Media flows directly between the browser and Stream, not through a Worker, Durable Object or database. Application routes handle identity, input ownership and authorized endpoint/token issuance.
|
|
100
|
-
|
|
101
|
-
Implement ICE negotiation (including gathering completion or Trickle ICE), failed-connection recovery and bounded retries. Retain the Location session resource from signaling, DELETE it on stop, close RTCPeerConnection and stop local camera/microphone tracks on failure, navigation and sign-out. Implement the player and creator UI for the product; this package is a management foundation, not a finished broadcast feature.
|
|
102
|
-
|
|
103
|
-
## Limits and acceptance
|
|
104
|
-
|
|
105
|
-
As reviewed October 16, 2026, WHIP ingest and WHEP playback must be paired. Recording, HLS/DASH playback of WHIP inputs, RTMP/SRT-to-WHEP bridging, restreaming and live viewer counts are unsupported. WebRTC usage appears in Stream analytics/billable usage; this does not promise broadcast or player-experience metrics. Delivery billing began October 15 at standard Stream rates; budget viewer-minutes (viewers multiplied by watch time), verify current pricing and account eligibility before activation.
|
|
106
|
-
|
|
107
|
-
Before claiming acceptance, exercise an authorized creator and viewer in separate browsers, denied creator/viewer access, cross-tenant input access, reconnect, camera denial, session teardown and usage visibility. Verify signed playback separately when selected. Scaffolding and local tests do not establish live video, latency or provider readiness.
|
|
108
|
-
|
|
109
|
-
- Release: https://developers.cloudflare.com/changelog/post/2026-10-15-stream-live-webrtc-ga/
|
|
110
|
-
- WebRTC and current limits: https://developers.cloudflare.com/stream/webrtc-beta/
|
|
111
|
-
- Browser tutorial: https://developers.cloudflare.com/stream/examples/browser-based-webrtc/
|
|
112
|
-
- Live input API: https://developers.cloudflare.com/api/resources/stream/subresources/live_inputs/methods/create/
|
|
113
|
-
- Pricing: https://developers.cloudflare.com/stream/pricing/
|
|
114
|
-
`;
|
package/dist/scaffold/void.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
/** Fresh-workspace conversion only. Existing applications keep their delivery engine. */
|
|
2
|
-
export declare function configureVoidDelivery(root: string): boolean;
|
|
3
|
-
/** Extend server declarations after transactional additions without evaluating config. */
|
|
4
|
-
export declare function refreshVoidEnvironment(root: string): void;
|
package/dist/scaffold/void.js
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import { existsSync, readFileSync, readdirSync, rmSync } from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
|
-
import { VOID_NODE_ENGINE, VOID_VERSION } from '../void.js';
|
|
4
|
-
import { VINEXT_DEPENDENCIES, WORKER_DEV_PORTS } from '../dependencies.js';
|
|
5
|
-
import { VINEXT_SERVER_OUTPUT_PLUGIN } from '../vinext.js';
|
|
6
|
-
import { json, patchPackage, put, readJson } from './files.js';
|
|
7
|
-
/** Keep Void's adapter paired with the Wrangler version validated by this stack. */
|
|
8
|
-
function pinVoidCloudflareAdapter(root) {
|
|
9
|
-
const pkg = readJson(root, 'package.json');
|
|
10
|
-
const pnpm = (pkg.pnpm ?? {});
|
|
11
|
-
patchPackage(root, 'package.json', {
|
|
12
|
-
pnpm: {
|
|
13
|
-
...pnpm,
|
|
14
|
-
overrides: {
|
|
15
|
-
...(pnpm.overrides ?? {}),
|
|
16
|
-
[`void@${VOID_VERSION}>@cloudflare/vite-plugin`]: VINEXT_DEPENDENCIES.devDependencies['@cloudflare/vite-plugin'],
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
/** Fresh-workspace conversion only. Existing applications keep their delivery engine. */
|
|
22
|
-
export function configureVoidDelivery(root) {
|
|
23
|
-
if (existsSync(path.join(root, 'apps/web/open-next.config.ts')) ||
|
|
24
|
-
existsSync(path.join(root, 'apps/mobile/worker/index.ts')))
|
|
25
|
-
return false;
|
|
26
|
-
for (const app of readdirSync(path.join(root, 'apps'))) {
|
|
27
|
-
const file = path.join(root, 'apps', app, 'wrangler.jsonc');
|
|
28
|
-
if (!existsSync(file))
|
|
29
|
-
continue;
|
|
30
|
-
const config = readJson(root, `apps/${app}/wrangler.jsonc`);
|
|
31
|
-
if (config.queues || config.pipelines || config.images || config.analytics_engine_datasets)
|
|
32
|
-
return false;
|
|
33
|
-
}
|
|
34
|
-
let configured = false;
|
|
35
|
-
for (const app of readdirSync(path.join(root, 'apps'))) {
|
|
36
|
-
const directory = `apps/${app}`;
|
|
37
|
-
const source = path.join(root, directory, 'wrangler.jsonc');
|
|
38
|
-
// OpenNext remains an explicit legacy recipe until its adapter is supported.
|
|
39
|
-
if (!existsSync(source) || existsSync(path.join(root, directory, 'open-next.config.ts')))
|
|
40
|
-
continue;
|
|
41
|
-
const cloudflare = readJson(root, `${directory}/wrangler.jsonc`);
|
|
42
|
-
delete cloudflare.$schema;
|
|
43
|
-
if (app !== 'web') {
|
|
44
|
-
cloudflare.main = 'src/void-entry.ts';
|
|
45
|
-
cloudflare.version_metadata = { binding: '__VOID_VERSION_METADATA' };
|
|
46
|
-
}
|
|
47
|
-
json(root, `${directory}/anhedral.cloudflare.json`, cloudflare);
|
|
48
|
-
rmSync(source);
|
|
49
|
-
put(root, `${directory}/void.config.ts`, `// Platform tooling requires this per-app declaration; resource bindings remain app-specific.
|
|
50
|
-
// fallow-ignore-file code-duplication
|
|
51
|
-
import { defineConfig } from 'void/config';
|
|
52
|
-
import declared from './anhedral.cloudflare.json';
|
|
53
|
-
|
|
54
|
-
// Unassigned placeholders are not provider identities. Void records real IDs
|
|
55
|
-
// in its lock, while Anhedral retains the declarative resource names.
|
|
56
|
-
const cloudflare = JSON.parse(JSON.stringify(declared, (key, value) =>
|
|
57
|
-
key === 'anhedral_name' || (typeof value === 'string' && value.startsWith('REPLACE_WITH_')) ? undefined : value,
|
|
58
|
-
));
|
|
59
|
-
|
|
60
|
-
// Enable only registry-declared capabilities with their exact binding names.
|
|
61
|
-
// Capability additions update this declaration without scanning other packages.
|
|
62
|
-
// Shared packages receive bindings through factories.
|
|
63
|
-
export default defineConfig({
|
|
64
|
-
target: 'cloudflare',
|
|
65
|
-
inference: {
|
|
66
|
-
appType: '${app === 'web' ? 'framework' : 'void'}',
|
|
67
|
-
scanDirs: ['src', 'app', 'lib'],
|
|
68
|
-
bindings: {
|
|
69
|
-
db: cloudflare.d1_databases?.[0]?.binding ?? false,
|
|
70
|
-
kv: cloudflare.kv_namespaces?.[0]?.binding ?? false,
|
|
71
|
-
storage: cloudflare.r2_buckets?.[0]?.binding ?? false,
|
|
72
|
-
ai: cloudflare.ai?.binding ?? false,
|
|
73
|
-
email: false,
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
cloudflare,
|
|
77
|
-
});
|
|
78
|
-
`);
|
|
79
|
-
const envKeys = new Map();
|
|
80
|
-
for (const filename of ['.dev.vars.example', '.env.example']) {
|
|
81
|
-
const file = path.join(root, directory, filename);
|
|
82
|
-
if (!existsSync(file))
|
|
83
|
-
continue;
|
|
84
|
-
for (const match of readFileSync(file, 'utf8').matchAll(/^([A-Z][A-Z0-9_]*)=(.*)$/gm))
|
|
85
|
-
envKeys.set(match[1], match[2]);
|
|
86
|
-
rmSync(file);
|
|
87
|
-
}
|
|
88
|
-
put(root, `${directory}/env.example`, '# Copy env.example to .env in this app directory. Void reads one local file per deployable app.\n# Production server values use void secret; VITE_* values must be supplied by the build environment.\n' +
|
|
89
|
-
[...envKeys].map(([key, value]) => `${key}=${value}`).join('\n') +
|
|
90
|
-
'\n');
|
|
91
|
-
const serverKeys = [...envKeys.keys()].filter((key) => !key.startsWith('NEXT_PUBLIC_') &&
|
|
92
|
-
!key.startsWith('VITE_') &&
|
|
93
|
-
!key.startsWith('EXPO_PUBLIC_'));
|
|
94
|
-
if (app !== 'web' && serverKeys.length) {
|
|
95
|
-
cloudflare.secrets = { required: serverKeys };
|
|
96
|
-
json(root, `${directory}/anhedral.cloudflare.json`, cloudflare);
|
|
97
|
-
}
|
|
98
|
-
put(root, `${directory}/env.ts`, `import { defineEnv${serverKeys.length ? ', string' : ''} } from 'void/env';\nexport default defineEnv({\n${serverKeys.map((key) => ` ${key}: string(),`).join('\n')}\n});\n`);
|
|
99
|
-
patchPackage(root, `${directory}/package.json`, {
|
|
100
|
-
devDependencies: { void: VOID_VERSION },
|
|
101
|
-
scripts: {
|
|
102
|
-
deploy: 'node ../../scripts/prepare-void-migrations.mjs && void deploy --platform cloudflare',
|
|
103
|
-
'env:check': 'void env check',
|
|
104
|
-
typecheck: `wrangler types --config anhedral.cloudflare.json${app === 'web' ? ' --env-interface CloudflareEnv cloudflare-env.d.ts' : ''} && tsc --noEmit`,
|
|
105
|
-
},
|
|
106
|
-
});
|
|
107
|
-
if (app === 'web') {
|
|
108
|
-
// Void owns the Cloudflare Vite adapter in this recipe; the legacy
|
|
109
|
-
// Vinext configuration's direct plugin dependency is no longer used.
|
|
110
|
-
const webPackage = readJson(root, `${directory}/package.json`);
|
|
111
|
-
const webDevDependencies = webPackage.devDependencies;
|
|
112
|
-
delete webDevDependencies['@cloudflare/vite-plugin'];
|
|
113
|
-
json(root, `${directory}/package.json`, webPackage);
|
|
114
|
-
if (existsSync(path.join(root, directory, 'tsconfig.json'))) {
|
|
115
|
-
const ts = readJson(root, `${directory}/tsconfig.json`);
|
|
116
|
-
ts.compilerOptions.resolveJsonModule = true;
|
|
117
|
-
json(root, `${directory}/tsconfig.json`, ts);
|
|
118
|
-
}
|
|
119
|
-
put(root, `${directory}/vite.config.ts`, `import { defineConfig } from 'vite';\nimport vinext from 'vinext';\nimport { voidPlugin } from 'void';\nexport default defineConfig({ plugins: [vinext(), voidPlugin(), ${VINEXT_SERVER_OUTPUT_PLUGIN}] });\n`);
|
|
120
|
-
patchPackage(root, `${directory}/package.json`, {
|
|
121
|
-
scripts: { preview: 'vite preview --host 127.0.0.1 --port 3000' },
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
const ports = WORKER_DEV_PORTS[app];
|
|
126
|
-
const schedules = cloudflare.triggers?.crons;
|
|
127
|
-
if (schedules?.length) {
|
|
128
|
-
put(root, `${directory}/crons/scheduled.ts`, `import application from '../src/index';
|
|
129
|
-
// Void validates authored cron triggers against source declarations. The
|
|
130
|
-
// standalone Worker entry retains the original scheduled event handler.
|
|
131
|
-
export const cron = ${JSON.stringify(schedules)};
|
|
132
|
-
export default application.scheduled;
|
|
133
|
-
`);
|
|
134
|
-
}
|
|
135
|
-
put(root, `${directory}/src/void-entry.ts`, `import application from './index';
|
|
136
|
-
export * from './index';
|
|
137
|
-
// Deployment readiness is distinct from product acceptance. Preserve original
|
|
138
|
-
// fetch, queue, scheduled and named Durable Object/Workflow exports.
|
|
139
|
-
type Worker = { fetch?: (request: Request, env: Env, ctx: ExecutionContext) => Response | Promise<Response> };
|
|
140
|
-
const original = application as unknown as Worker;
|
|
141
|
-
function readiness(env: Env): Response {
|
|
142
|
-
return Response.json({ ready: true, versionId: env.__VOID_VERSION_METADATA?.id }, { headers: { 'cache-control': 'no-store' } });
|
|
143
|
-
}
|
|
144
|
-
export default {
|
|
145
|
-
...application,
|
|
146
|
-
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
|
|
147
|
-
if (request.method === 'GET' && new URL(request.url).pathname === '/__void/ready') {
|
|
148
|
-
return readiness(env);
|
|
149
|
-
}
|
|
150
|
-
return original.fetch ? original.fetch.call(application, request, env, ctx) : new Response('Not found', { status: 404 });
|
|
151
|
-
},
|
|
152
|
-
};
|
|
153
|
-
`);
|
|
154
|
-
put(root, `${directory}/routes/README.md`, '# Standalone Worker delivery\n\nVoid 0.27 requires a backend convention directory to classify a Worker deployment. This reserved directory contains no Void handlers. The Cloudflare Vite plugin builds src/void-entry.ts, which adds deployment readiness and preserves the application handlers and exported classes from src/index.ts. Do not add a second router here without reviewing the application architecture.\n');
|
|
155
|
-
put(root, `${directory}/vite.config.ts`, `import { defineConfig } from 'vite';\nimport { cloudflare } from '@cloudflare/vite-plugin';\n// Void generates the deployment config before its fresh build. Local builds\n// use the same explicit declaration without provisioning remote resources.\nexport default defineConfig({ plugins: [cloudflare({ configPath: process.env.VOID_CLOUDFLARE_DEPLOY_BUILD ? '.void-wrangler.jsonc' : 'anhedral.cloudflare.json', inspectorPort: ${ports.inspector}, viteEnvironment: { name: 'ssr' } })], server: { host: '127.0.0.1', port: ${ports.http}, strictPort: true } });\n`);
|
|
156
|
-
patchPackage(root, `${directory}/package.json`, {
|
|
157
|
-
devDependencies: {
|
|
158
|
-
vite: VINEXT_DEPENDENCIES.devDependencies.vite,
|
|
159
|
-
'@cloudflare/vite-plugin': VINEXT_DEPENDENCIES.devDependencies['@cloudflare/vite-plugin'],
|
|
160
|
-
},
|
|
161
|
-
scripts: {
|
|
162
|
-
dev: 'vite dev',
|
|
163
|
-
build: 'vite build',
|
|
164
|
-
preview: `vite preview --host 127.0.0.1 --port ${ports.http}`,
|
|
165
|
-
},
|
|
166
|
-
});
|
|
167
|
-
const ts = readJson(root, `${directory}/tsconfig.json`);
|
|
168
|
-
const compiler = ts.compilerOptions;
|
|
169
|
-
compiler.resolveJsonModule = true;
|
|
170
|
-
ts.include = [
|
|
171
|
-
'src/**/*.ts',
|
|
172
|
-
'worker-configuration.d.ts',
|
|
173
|
-
'vite.config.ts',
|
|
174
|
-
'void.config.ts',
|
|
175
|
-
'env.ts',
|
|
176
|
-
];
|
|
177
|
-
json(root, `${directory}/tsconfig.json`, ts);
|
|
178
|
-
}
|
|
179
|
-
const migrateFile = path.join(root, 'packages/db/src/migrate.ts');
|
|
180
|
-
if (existsSync(migrateFile)) {
|
|
181
|
-
const migrateSource = readFileSync(migrateFile, 'utf8');
|
|
182
|
-
put(root, 'packages/db/src/migrate.ts', migrateSource.replaceAll(`apps/${app}/wrangler.jsonc`, `apps/${app}/anhedral.cloudflare.json`));
|
|
183
|
-
}
|
|
184
|
-
configured = true;
|
|
185
|
-
}
|
|
186
|
-
if (configured) {
|
|
187
|
-
pinVoidCloudflareAdapter(root);
|
|
188
|
-
patchPackage(root, 'package.json', { engines: { node: VOID_NODE_ENGINE } });
|
|
189
|
-
// The standalone generated preparation module uses only Node builtins and
|
|
190
|
-
// is byte-identical to the version exercised by Anhedral delivery tests.
|
|
191
|
-
put(root, 'scripts/void-migrations.mjs', readFileSync(new URL('../void-migrations.js', import.meta.url), 'utf8'));
|
|
192
|
-
put(root, 'scripts/prepare-void-migrations.mjs', `import { readFileSync } from 'node:fs';
|
|
193
|
-
import { fileURLToPath } from 'node:url';
|
|
194
|
-
import path from 'node:path';
|
|
195
|
-
import { prepareVoidMigrations } from './void-migrations.mjs';
|
|
196
|
-
const root = fileURLToPath(new URL('../', import.meta.url));
|
|
197
|
-
const directory = process.cwd();
|
|
198
|
-
const config = JSON.parse(readFileSync(path.join(directory, 'anhedral.cloudflare.json'), 'utf8'));
|
|
199
|
-
prepareVoidMigrations(root, directory, config);
|
|
200
|
-
`);
|
|
201
|
-
}
|
|
202
|
-
return configured;
|
|
203
|
-
}
|
|
204
|
-
/** Extend server declarations after transactional additions without evaluating config. */
|
|
205
|
-
export function refreshVoidEnvironment(root) {
|
|
206
|
-
let configured = false;
|
|
207
|
-
for (const app of readdirSync(path.join(root, 'apps'))) {
|
|
208
|
-
const directory = `apps/${app}`;
|
|
209
|
-
if (!existsSync(path.join(root, directory, 'void.config.ts')))
|
|
210
|
-
continue;
|
|
211
|
-
configured = true;
|
|
212
|
-
const schemaFile = path.join(root, directory, 'env.ts');
|
|
213
|
-
if (!existsSync(schemaFile))
|
|
214
|
-
continue;
|
|
215
|
-
let schema = readFileSync(schemaFile, 'utf8');
|
|
216
|
-
const local = path.join(root, directory, 'env.example');
|
|
217
|
-
let example = existsSync(local) ? readFileSync(local, 'utf8') : '';
|
|
218
|
-
// Recipe additions use legacy names before this fresh staged conversion.
|
|
219
|
-
for (const filename of ['.env.example', '.dev.vars.example']) {
|
|
220
|
-
const file = path.join(root, directory, filename);
|
|
221
|
-
if (!existsSync(file))
|
|
222
|
-
continue;
|
|
223
|
-
for (const line of readFileSync(file, 'utf8').split('\n')) {
|
|
224
|
-
const key = /^([A-Z][A-Z0-9_]*)=/.exec(line)?.[1];
|
|
225
|
-
if (key && !example.split('\n').some((entry) => entry.startsWith(`${key}=`))) {
|
|
226
|
-
example += (example.endsWith('\n') ? '' : '\n') + line + '\n';
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
rmSync(file);
|
|
230
|
-
}
|
|
231
|
-
put(root, `${directory}/env.example`, example);
|
|
232
|
-
const keys = [...example.matchAll(/^([A-Z][A-Z0-9_]*)=/gm)].map((match) => match[1]);
|
|
233
|
-
const missing = [...new Set(keys)].filter((key) => !key.startsWith('NEXT_PUBLIC_') &&
|
|
234
|
-
!key.startsWith('VITE_') &&
|
|
235
|
-
!key.startsWith('EXPO_PUBLIC_') &&
|
|
236
|
-
!new RegExp(String.raw `\b${key}\s*:`).test(schema));
|
|
237
|
-
if (app !== 'web' && existsSync(path.join(root, directory, 'anhedral.cloudflare.json'))) {
|
|
238
|
-
const configFile = `${directory}/anhedral.cloudflare.json`;
|
|
239
|
-
const config = readJson(root, configFile);
|
|
240
|
-
const serverKeys = [...new Set(keys)].filter((key) => !key.startsWith('NEXT_PUBLIC_') &&
|
|
241
|
-
!key.startsWith('VITE_') &&
|
|
242
|
-
!key.startsWith('EXPO_PUBLIC_'));
|
|
243
|
-
const secrets = (config.secrets ?? {});
|
|
244
|
-
config.secrets = {
|
|
245
|
-
...secrets,
|
|
246
|
-
required: [...new Set([...(secrets.required ?? []), ...serverKeys])],
|
|
247
|
-
};
|
|
248
|
-
json(root, configFile, config);
|
|
249
|
-
}
|
|
250
|
-
if (!missing.length)
|
|
251
|
-
continue;
|
|
252
|
-
if (!schema.includes('defineEnv({'))
|
|
253
|
-
throw new Error(`Review ${directory}/env.ts before adding server environment keys.`);
|
|
254
|
-
if (!/import\s*\{[^}]*\bstring\b[^}]*\}\s*from\s*['"]void\/env['"]/.test(schema)) {
|
|
255
|
-
schema = schema.replace(/import\s*\{([^}]*)\}\s*from\s*(['"]void\/env['"])/, 'import { $1, string } from $2');
|
|
256
|
-
}
|
|
257
|
-
schema = schema.replace('defineEnv({', `defineEnv({\n${missing.map((key) => ` ${key}: string(),`).join('\n')}`);
|
|
258
|
-
put(root, `${directory}/env.ts`, schema);
|
|
259
|
-
}
|
|
260
|
-
if (configured) {
|
|
261
|
-
pinVoidCloudflareAdapter(root);
|
|
262
|
-
patchPackage(root, 'package.json', { engines: { node: VOID_NODE_ENGINE } });
|
|
263
|
-
}
|
|
264
|
-
}
|
package/dist/scaffold/web.d.ts
DELETED