anhedral 0.11.1 → 0.12.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 +126 -69
- package/dist/bin.js +48 -493
- package/dist/capabilities.d.ts +3 -3
- package/dist/capability-contract.js +4 -0
- package/dist/cli-arguments.d.ts +8 -0
- package/dist/cli-arguments.js +32 -0
- package/dist/cli-commands.d.ts +3 -0
- package/dist/cli-commands.js +114 -0
- package/dist/cli-delivery.d.ts +3 -0
- package/dist/cli-delivery.js +172 -0
- package/dist/cli-output.js +231 -205
- package/dist/delivery-evidence.d.ts +62 -0
- package/dist/delivery-evidence.js +186 -0
- package/dist/delivery.d.ts +3 -40
- package/dist/delivery.js +4 -181
- package/dist/dependencies.d.ts +1 -0
- package/dist/dependencies.js +2 -0
- package/dist/mobile-delivery.d.ts +21 -44
- package/dist/mobile-delivery.js +127 -80
- package/dist/provider-auth.js +3 -3
- package/dist/scaffold/documentation.js +1 -0
- package/dist/scaffold/stream.d.ts +2 -0
- package/dist/scaffold/stream.js +114 -0
- package/dist/service-readers.js +1 -1
- package/dist/services-command.js +8 -6
- package/dist/ship.d.ts +15 -15
- package/dist/stack-registry.d.ts +4 -2
- package/dist/stack-registry.js +16 -0
- package/dist/transaction-lock.d.ts +15 -0
- package/dist/transaction-lock.js +227 -0
- package/dist/transaction.js +2 -208
- package/dist/vercel-project.d.ts +101 -0
- package/dist/vercel-project.js +305 -0
- package/dist/vercel.d.ts +3 -36
- package/dist/vercel.js +3 -300
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/docs/software-factory.md +528 -0
- package/docs/stack-standard.md +196 -121
- package/docs/verification.md +444 -0
- package/package.json +3 -6
- package/docs/cli-design.md +0 -67
- package/docs/delivery-workflow.md +0 -98
- package/docs/plugin-ui.md +0 -102
- package/docs/provider-configuration.md +0 -116
- package/docs/void-verification.md +0 -185
package/dist/mobile-delivery.js
CHANGED
|
@@ -68,7 +68,7 @@ export async function buildMobileApplication(root, options, run = defaultRunner)
|
|
|
68
68
|
await executeMobileBuild(root, { ...options, dryRun: true }, run);
|
|
69
69
|
return withLifecycleOperation(root, 'mobile', run, (session) => session.phase('mobile-build', () => executeMobileBuild(root, options, run)));
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
function mobileConfiguration(root, options) {
|
|
72
72
|
root = realpathSync(root);
|
|
73
73
|
if (!['ios', 'android'].includes(options.platform) ||
|
|
74
74
|
!/^[a-z][a-z0-9-]{0,63}$/.test(options.profile))
|
|
@@ -110,15 +110,9 @@ async function executeMobileBuild(root, options, run = defaultRunner) {
|
|
|
110
110
|
'--json',
|
|
111
111
|
'--no-wait',
|
|
112
112
|
];
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
profile: options.profile,
|
|
117
|
-
command: ['pnpm', ...args],
|
|
118
|
-
mutation: false,
|
|
119
|
-
storeSubmission: false,
|
|
120
|
-
integrations: planProviderProvisioning(root),
|
|
121
|
-
};
|
|
113
|
+
return { root, options, directory, profile, selectedEnvironment, args };
|
|
114
|
+
}
|
|
115
|
+
function readMobileApplication(directory) {
|
|
122
116
|
const app = JSON.parse(readBoundedFile(path.join(directory, 'app.json'), MAX_PROJECT_JSON_BYTES).toString('utf8')).expo;
|
|
123
117
|
if (['app.config.js', 'app.config.ts'].some((file) => existsSync(path.join(directory, file))))
|
|
124
118
|
throw new Error('Automatic EAS setup requires a static app.json with explicit owner and slug.');
|
|
@@ -127,57 +121,46 @@ async function executeMobileBuild(root, options, run = defaultRunner) {
|
|
|
127
121
|
typeof app.slug !== 'string' ||
|
|
128
122
|
!/^[a-zA-Z0-9_-]+$/.test(app.slug))
|
|
129
123
|
throw new Error('Set the intended Expo owner and slug in app.json before shipping.');
|
|
124
|
+
return app;
|
|
125
|
+
}
|
|
126
|
+
function mobileEnvironment() {
|
|
130
127
|
const environment = { ...process.env, CI: '1', NO_COLOR: '1' };
|
|
131
128
|
// Expo keeps its own login credential; server/provider keys never reach native builds.
|
|
132
129
|
for (const key of [...Object.values(CREDENTIALS), ...RUNTIME_KEYS])
|
|
133
130
|
if (!key.startsWith('EXPO_PUBLIC_'))
|
|
134
131
|
delete environment[key];
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
132
|
+
return environment;
|
|
133
|
+
}
|
|
134
|
+
async function mobileSource(root, environment, run) {
|
|
135
|
+
if (realpathSync((await run('git', ['rev-parse', '--show-toplevel'], root, environment)).trim()) !==
|
|
136
|
+
root ||
|
|
137
|
+
(await run('git', ['status', '--porcelain'], root, environment)).trim())
|
|
138
|
+
throw new Error('Mobile delivery requires a clean application Git repository.');
|
|
139
|
+
const commit = (await run('git', ['rev-parse', 'HEAD'], root, environment)).trim();
|
|
140
|
+
if (!/^[a-f0-9]{40,64}$/.test(commit))
|
|
141
|
+
throw new Error('Invalid mobile source commit.');
|
|
142
|
+
return commit;
|
|
143
|
+
}
|
|
144
|
+
const easCli = ['dlx', `eas-cli@${EAS_CLI_VERSION}`];
|
|
145
|
+
async function linkMobileProject({ configuration: { directory }, app, environment, run, }) {
|
|
146
|
+
const cli = easCli;
|
|
147
|
+
await run('pnpm', [...cli, 'project:init', '--non-interactive', '--force'], directory, environment);
|
|
148
|
+
const linked = JSON.parse(readBoundedFile(path.join(directory, 'app.json'), MAX_PROJECT_JSON_BYTES).toString('utf8')).expo;
|
|
149
|
+
if (linked?.owner !== app.owner ||
|
|
150
|
+
linked.slug !== app.slug ||
|
|
151
|
+
typeof linked.extra?.eas?.projectId !== 'string' ||
|
|
152
|
+
!/^[a-f0-9-]{36}$/i.test(linked.extra.eas.projectId))
|
|
153
|
+
throw new Error('EAS did not confirm a project link for the selected owner and slug. Inspect the account before retrying.');
|
|
154
|
+
return {
|
|
155
|
+
state: 'configuration-required',
|
|
156
|
+
deployed: false,
|
|
157
|
+
storeSubmission: false,
|
|
158
|
+
nextAction: 'Review and commit the EAS project link written to app.json, then run ship again.',
|
|
143
159
|
};
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
if ((await source()) !== initialCommit)
|
|
149
|
-
throw new Error('Source changed during mobile checks.');
|
|
150
|
-
const configured = await provisionSelectedProviders(root, false, run);
|
|
151
|
-
if (!configured.ready)
|
|
152
|
-
return {
|
|
153
|
-
state: 'provider-configuration-required',
|
|
154
|
-
deployed: false,
|
|
155
|
-
integrations: configured,
|
|
156
|
-
storeSubmission: false,
|
|
157
|
-
};
|
|
158
|
-
const runtime = configuredRuntime(root);
|
|
159
|
-
const commit = await source();
|
|
160
|
-
if (commit !== initialCommit)
|
|
161
|
-
throw new Error('Source changed during provider configuration.');
|
|
162
|
-
const cli = ['dlx', `eas-cli@${EAS_CLI_VERSION}`];
|
|
163
|
-
if (!app.extra?.eas?.projectId) {
|
|
164
|
-
await run('pnpm', [...cli, 'project:init', '--non-interactive', '--force'], directory, environment);
|
|
165
|
-
const linked = JSON.parse(readBoundedFile(path.join(directory, 'app.json'), MAX_PROJECT_JSON_BYTES).toString('utf8')).expo;
|
|
166
|
-
if (linked?.owner !== app.owner ||
|
|
167
|
-
linked.slug !== app.slug ||
|
|
168
|
-
typeof linked.extra?.eas?.projectId !== 'string' ||
|
|
169
|
-
!/^[a-f0-9-]{36}$/i.test(linked.extra.eas.projectId))
|
|
170
|
-
throw new Error('EAS did not confirm a project link for the selected owner and slug. Inspect the account before retrying.');
|
|
171
|
-
return {
|
|
172
|
-
state: 'configuration-required',
|
|
173
|
-
deployed: false,
|
|
174
|
-
storeSubmission: false,
|
|
175
|
-
nextAction: 'Review and commit the EAS project link written to app.json, then run ship again.',
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
const projectId = app.extra.eas.projectId;
|
|
179
|
-
if (typeof projectId !== 'string' || !/^[a-f0-9-]{36}$/i.test(projectId))
|
|
180
|
-
throw new Error('Invalid EAS project ID.');
|
|
160
|
+
}
|
|
161
|
+
async function verifyMobileProject(session, projectId) {
|
|
162
|
+
const { configuration: { directory }, app, environment, run, } = session;
|
|
163
|
+
const cli = easCli;
|
|
181
164
|
const remote = await run('pnpm', [...cli, 'project:info'], directory, environment);
|
|
182
165
|
const remoteName = remote
|
|
183
166
|
.split(/\r?\n/)
|
|
@@ -191,7 +174,10 @@ async function executeMobileBuild(root, options, run = defaultRunner) {
|
|
|
191
174
|
.split(/\s+/)[1];
|
|
192
175
|
if (remoteId !== projectId || remoteName !== `@${app.owner}/${app.slug}`)
|
|
193
176
|
throw new Error('EAS project identity differs from the selected owner and project.');
|
|
194
|
-
|
|
177
|
+
}
|
|
178
|
+
async function configureMobileEnvironment(session, values) {
|
|
179
|
+
const { configuration: { directory, selectedEnvironment }, environment, run, } = session;
|
|
180
|
+
const cli = easCli;
|
|
195
181
|
if (values && Object.keys(values).length) {
|
|
196
182
|
const file = path.join(tmpdir(), `anhedral-expo-${randomUUID()}.env`);
|
|
197
183
|
try {
|
|
@@ -204,6 +190,12 @@ async function executeMobileBuild(root, options, run = defaultRunner) {
|
|
|
204
190
|
rmSync(file, { force: true });
|
|
205
191
|
}
|
|
206
192
|
}
|
|
193
|
+
}
|
|
194
|
+
async function requestMobileBuild(session, selection) {
|
|
195
|
+
const { configuration: { root, options, directory, args }, environment, run, } = session;
|
|
196
|
+
const { commit, projectId, values } = selection;
|
|
197
|
+
const cli = easCli;
|
|
198
|
+
const source = () => mobileSource(root, environment, run);
|
|
207
199
|
let builds;
|
|
208
200
|
let expectedBuildId;
|
|
209
201
|
const pendingFile = path.join(root, '.anhedral/mobile-build.pending.json');
|
|
@@ -236,25 +228,48 @@ async function executeMobileBuild(root, options, run = defaultRunner) {
|
|
|
236
228
|
catch {
|
|
237
229
|
throw new Error('EAS build did not return verified completion; inspect the selected Expo project before retrying.');
|
|
238
230
|
}
|
|
231
|
+
return { builds, expectedBuildId, pendingFile };
|
|
232
|
+
}
|
|
233
|
+
function validateMobileBuild(session, selection, builds, expectedBuildId) {
|
|
234
|
+
const { configuration: { options, profile, selectedEnvironment }, app, } = session;
|
|
235
|
+
const { commit, projectId } = selection;
|
|
239
236
|
if (!Array.isArray(builds) || builds.length !== 1)
|
|
240
237
|
throw new Error('EAS returned an unexpected build selection.');
|
|
241
238
|
const build = builds[0];
|
|
242
|
-
const downloadUrl = artifactUrl(build?.artifacts?.applicationArchiveUrl ?? build?.artifacts?.buildUrl);
|
|
243
239
|
if (typeof build?.id !== 'string' || !/^[a-zA-Z0-9-]{1,255}$/.test(build.id))
|
|
244
240
|
throw new Error('EAS did not return a valid build ID.');
|
|
245
241
|
if (build.project?.id !== projectId ||
|
|
246
242
|
build.project?.ownerAccount?.name !== app.owner ||
|
|
247
243
|
build.project?.slug !== app.slug)
|
|
248
244
|
throw new Error('EAS build belongs to a different project.');
|
|
245
|
+
validateBuildProfile(build, options, profile, selectedEnvironment);
|
|
246
|
+
if (build.gitCommitHash !== commit)
|
|
247
|
+
throw new Error('EAS build source differs from the selected source commit.');
|
|
248
|
+
if (expectedBuildId && build.id !== expectedBuildId)
|
|
249
|
+
throw new Error('EAS returned a different build than the recorded selection.');
|
|
250
|
+
return build;
|
|
251
|
+
}
|
|
252
|
+
function validateBuildProfile(build, options, profile, selectedEnvironment) {
|
|
249
253
|
if (build.platform !== options.platform.toUpperCase() ||
|
|
250
254
|
build.buildProfile !== options.profile ||
|
|
251
255
|
(build.environment !== undefined && build.environment !== selectedEnvironment) ||
|
|
252
256
|
(options.platform === 'ios' && build.isForIosSimulator !== (profile.ios?.simulator === true)))
|
|
253
257
|
throw new Error('EAS build platform, profile or environment differs from the selected configuration.');
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (
|
|
257
|
-
|
|
258
|
+
}
|
|
259
|
+
function mobileArtifact(options, profile) {
|
|
260
|
+
if (options.platform === 'ios')
|
|
261
|
+
return profile.ios?.simulator === true ? 'ios-simulator' : 'ipa';
|
|
262
|
+
return profile.android?.buildType === 'apk' ||
|
|
263
|
+
profile.distribution === 'internal' ||
|
|
264
|
+
profile.developmentClient === true
|
|
265
|
+
? 'apk'
|
|
266
|
+
: 'aab';
|
|
267
|
+
}
|
|
268
|
+
async function recordMobileBuild(session, selection, build, pendingFile) {
|
|
269
|
+
const { configuration: { root, options, profile }, app, environment, run, } = session;
|
|
270
|
+
const { commit, projectId } = selection;
|
|
271
|
+
const source = () => mobileSource(root, environment, run);
|
|
272
|
+
const downloadUrl = artifactUrl(build.artifacts?.applicationArchiveUrl ?? build.artifacts?.buildUrl);
|
|
258
273
|
atomicJson(pendingFile, {
|
|
259
274
|
schemaVersion: 1,
|
|
260
275
|
status: 'queued',
|
|
@@ -265,7 +280,7 @@ async function executeMobileBuild(root, options, run = defaultRunner) {
|
|
|
265
280
|
buildId: build.id,
|
|
266
281
|
});
|
|
267
282
|
const buildPage = `https://expo.dev/accounts/${app.owner}/projects/${app.slug}/builds/${build.id}`;
|
|
268
|
-
if (['NEW', 'IN_QUEUE', 'IN_PROGRESS', 'PENDING_CANCEL'].includes(build.status))
|
|
283
|
+
if (['NEW', 'IN_QUEUE', 'IN_PROGRESS', 'PENDING_CANCEL'].includes(build.status ?? ''))
|
|
269
284
|
return {
|
|
270
285
|
schemaVersion: 1,
|
|
271
286
|
state: 'building',
|
|
@@ -281,21 +296,14 @@ async function executeMobileBuild(root, options, run = defaultRunner) {
|
|
|
281
296
|
throw new Error('EAS has not confirmed a completed downloadable build. Inspect the recorded build before retrying.');
|
|
282
297
|
if ((await source()) !== commit)
|
|
283
298
|
throw new Error('Source changed during mobile build; do not treat this artifact as the current release.');
|
|
284
|
-
const owner = build.project?.ownerAccount?.name;
|
|
285
|
-
const slug = build.project?.slug;
|
|
286
|
-
const buildPageUrl = typeof owner === 'string' &&
|
|
287
|
-
/^[a-zA-Z0-9_-]+$/.test(owner) &&
|
|
288
|
-
typeof slug === 'string' &&
|
|
289
|
-
/^[a-zA-Z0-9_-]+$/.test(slug)
|
|
290
|
-
? `https://expo.dev/accounts/${owner}/projects/${slug}/builds/${build.id}`
|
|
291
|
-
: undefined;
|
|
292
299
|
const result = {
|
|
293
300
|
schemaVersion: 1,
|
|
294
301
|
projectId,
|
|
295
302
|
owner: app.owner,
|
|
296
303
|
slug: app.slug,
|
|
297
304
|
recordedAt: new Date().toISOString(),
|
|
298
|
-
|
|
305
|
+
// Identity validation already matched the provider owner/slug to the local app.
|
|
306
|
+
buildPageUrl: buildPage,
|
|
299
307
|
commit,
|
|
300
308
|
platform: options.platform,
|
|
301
309
|
profile: options.profile,
|
|
@@ -303,17 +311,56 @@ async function executeMobileBuild(root, options, run = defaultRunner) {
|
|
|
303
311
|
downloadUrl,
|
|
304
312
|
state: 'built',
|
|
305
313
|
storeSubmission: false,
|
|
306
|
-
artifact: options
|
|
307
|
-
? profile.ios?.simulator === true
|
|
308
|
-
? 'ios-simulator'
|
|
309
|
-
: 'ipa'
|
|
310
|
-
: profile.android?.buildType === 'apk' ||
|
|
311
|
-
profile.distribution === 'internal' ||
|
|
312
|
-
profile.developmentClient === true
|
|
313
|
-
? 'apk'
|
|
314
|
-
: 'aab',
|
|
314
|
+
artifact: mobileArtifact(options, profile),
|
|
315
315
|
};
|
|
316
316
|
atomicJson(path.join(root, '.anhedral/mobile-build.json'), result);
|
|
317
317
|
rmSync(pendingFile, { force: true });
|
|
318
318
|
return result;
|
|
319
319
|
}
|
|
320
|
+
async function executeMobileBuild(root, options, run) {
|
|
321
|
+
const configuration = mobileConfiguration(root, options);
|
|
322
|
+
root = configuration.root;
|
|
323
|
+
if (options.dryRun)
|
|
324
|
+
return {
|
|
325
|
+
platform: options.platform,
|
|
326
|
+
profile: options.profile,
|
|
327
|
+
command: ['pnpm', ...configuration.args],
|
|
328
|
+
mutation: false,
|
|
329
|
+
storeSubmission: false,
|
|
330
|
+
integrations: planProviderProvisioning(root),
|
|
331
|
+
};
|
|
332
|
+
const app = readMobileApplication(configuration.directory);
|
|
333
|
+
const environment = mobileEnvironment();
|
|
334
|
+
const session = { configuration, app, environment, run };
|
|
335
|
+
const source = () => mobileSource(root, environment, run);
|
|
336
|
+
const initialCommit = await source();
|
|
337
|
+
// Unknown submissions must stop before checks, provisioning or remote configuration.
|
|
338
|
+
pendingBuild(root, initialCommit, options, app.extra?.eas?.projectId);
|
|
339
|
+
await run('pnpm', ['run', 'check'], root, environment);
|
|
340
|
+
if ((await source()) !== initialCommit)
|
|
341
|
+
throw new Error('Source changed during mobile checks.');
|
|
342
|
+
const configured = await provisionSelectedProviders(root, false, run);
|
|
343
|
+
if (!configured.ready)
|
|
344
|
+
return {
|
|
345
|
+
state: 'provider-configuration-required',
|
|
346
|
+
deployed: false,
|
|
347
|
+
integrations: configured,
|
|
348
|
+
storeSubmission: false,
|
|
349
|
+
};
|
|
350
|
+
const runtime = configuredRuntime(root);
|
|
351
|
+
const commit = await source();
|
|
352
|
+
if (commit !== initialCommit)
|
|
353
|
+
throw new Error('Source changed during provider configuration.');
|
|
354
|
+
if (!app.extra?.eas?.projectId)
|
|
355
|
+
return linkMobileProject(session);
|
|
356
|
+
const projectId = app.extra.eas.projectId;
|
|
357
|
+
if (typeof projectId !== 'string' || !/^[a-f0-9-]{36}$/i.test(projectId))
|
|
358
|
+
throw new Error('Invalid EAS project ID.');
|
|
359
|
+
await verifyMobileProject(session, projectId);
|
|
360
|
+
const values = runtimeTargets(root, runtime)['apps/mobile/.env.local'];
|
|
361
|
+
await configureMobileEnvironment(session, values);
|
|
362
|
+
const selection = { commit, projectId, values };
|
|
363
|
+
const { builds, expectedBuildId, pendingFile } = await requestMobileBuild(session, selection);
|
|
364
|
+
const build = validateMobileBuild(session, selection, builds, expectedBuildId);
|
|
365
|
+
return recordMobileBuild(session, selection, build, pendingFile);
|
|
366
|
+
}
|
package/dist/provider-auth.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EAS_CLI_VERSION, STACK_DEPENDENCIES } from './dependencies.js';
|
|
1
|
+
import { EAS_CLI_VERSION, STACK_DEPENDENCIES, VERCEL_CLI_VERSION } from './dependencies.js';
|
|
2
2
|
import { realpathSync } from 'node:fs';
|
|
3
3
|
import { spawn } from 'node:child_process';
|
|
4
4
|
import { readProjectSection } from './project-config.js';
|
|
@@ -31,8 +31,8 @@ export const PROVIDER_AUTH = [
|
|
|
31
31
|
{
|
|
32
32
|
id: 'vercel',
|
|
33
33
|
products: [],
|
|
34
|
-
login: ['pnpm', 'dlx',
|
|
35
|
-
identity: ['pnpm', 'dlx',
|
|
34
|
+
login: ['pnpm', 'dlx', `vercel@${VERCEL_CLI_VERSION}`, 'login'],
|
|
35
|
+
identity: ['pnpm', 'dlx', `vercel@${VERCEL_CLI_VERSION}`, 'whoami'],
|
|
36
36
|
setup: 'Connect the intended Vercel team and project before shipping.',
|
|
37
37
|
},
|
|
38
38
|
...INTEGRATION_PROVIDERS.map((id) => {
|
|
@@ -55,6 +55,7 @@ ${has('better-auth') ? 'Core Better Auth tables are included in the Drizzle sche
|
|
|
55
55
|
${has('clerk') ? `${has('next') || has('vinext') ? 'The web starter includes ClerkProvider, middleware and sign-in/sign-up pages. Configure NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY and server-only CLERK_SECRET_KEY. ' : ''}${has('hono') ? 'packages/auth exports a Clerk request authentication helper. Configure its server secret and publishable key, supply explicit authorized origins, and wire it into product routes; the API health route remains public. ' : ''}Authentication does not establish resource authorization.\n` : ''}
|
|
56
56
|
${has('r2') ? 'FILES is a private R2 binding. Implement authentication and file-level authorization before exposing file routes. Clients never receive R2 credentials.\n' : ''}
|
|
57
57
|
${has('neon-realtime') ? 'Neon Realtime is an optional beta live SQL foundation, separate from Durable Object rooms. Read [packages/neon-realtime/README.md](packages/neon-realtime/README.md) for the server/client factories and Drizzle adapter. Manually enable the intended branch, configure exact allowed origins and set server-only NEON_REALTIME_SECRET with DATABASE_URL; NEON_REALTIME_URL is public client transport configuration. Authenticate sealing requests and scope every query to verified user/tenant access. Implement subscriptions, authorized renewal and isolation tests; RLS, automatic Realtime provisioning and a public SQL endpoint are not provided. Live behavior remains unverified.\n' : ''}
|
|
58
|
+
${has('stream') ? 'Cloudflare Stream provides optional one-to-many WHIP/WHEP live video. Follow packages/stream/README.md and import the management factory only from @workspace/stream/server. Configure server-only STREAM_API_TOKEN and STREAM_ACCOUNT_ID manually. Authorize creators and input ownership; never return secret WHIP URLs to viewers. Implement playback token issuance for private media, browser signaling/UI and session cleanup. Stream activation, live inputs and runtime credentials are not automatically provisioned; live behavior remains unverified.\n' : ''}
|
|
58
59
|
${has('realtime') ? 'Durable Object rooms support hibernating WebSockets; the public entrypoint remains disabled until room authorization and short-lived tickets are implemented.\n' : ''}
|
|
59
60
|
${has('queues') ? 'Queue processing retries unimplemented jobs and uses a dead-letter queue. Add product processing and transactional idempotency before acknowledging messages.\n' : ''}
|
|
60
61
|
${has('basin') ? 'Basin uses a Pipelines stream binding. Configure its stream, sink, R2/catalog and SQL in client-owned infrastructure; it is distinct from operational logs.\n' : ''}
|
|
@@ -0,0 +1,114 @@
|
|
|
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/service-readers.js
CHANGED
|
@@ -81,7 +81,7 @@ async function d1Query(service, request, sql, params = []) {
|
|
|
81
81
|
export async function listServiceTables(service, request) {
|
|
82
82
|
if (service.kind !== 'd1')
|
|
83
83
|
throw new Error('Schema browsing is supported for D1 databases.');
|
|
84
|
-
const rows = await d1Query(service, request, "SELECT name FROM sqlite_schema WHERE type = 'table' AND name NOT
|
|
84
|
+
const rows = await d1Query(service, request, "SELECT name FROM sqlite_schema WHERE type = 'table' AND name NOT GLOB 'sqlite_*' AND name NOT GLOB '_cf_*' ORDER BY name LIMIT 1001");
|
|
85
85
|
if (rows.length > 1000)
|
|
86
86
|
throw new Error('Database schema exceeds its table limit.');
|
|
87
87
|
return rows.map((row) => {
|
package/dist/services-command.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { CliArgumentError } from './cli-arguments.js';
|
|
2
3
|
import { resolveIntegrationService } from './integration-service-readers.js';
|
|
3
4
|
import { inspectApplication } from './project-inspector.js';
|
|
4
5
|
import { resolveService, serviceCapabilities, unboundResourceSelectors, } from './service-descriptor.js';
|
|
5
6
|
import { ServiceDeletionStore } from './service-deletion.js';
|
|
6
7
|
import { catalogDirectory } from './catalog-registration.js';
|
|
7
8
|
import { serviceOperation } from './service-operations.js';
|
|
9
|
+
const argumentError = (message) => new CliArgumentError(message, 'Run anhedral services --help.');
|
|
8
10
|
export async function runServiceCommand(root, input) {
|
|
9
11
|
const args = input.filter((arg) => arg !== '--json');
|
|
10
12
|
const action = args.shift();
|
|
11
13
|
const actions = ['list', 'status', 'metrics', 'tables', 'data', 'delete-plan', 'delete'];
|
|
12
14
|
if (!action || !actions.includes(action))
|
|
13
|
-
throw
|
|
15
|
+
throw argumentError('Choose a supported services operation.');
|
|
14
16
|
if (action === 'list') {
|
|
15
17
|
if (args.length)
|
|
16
|
-
throw
|
|
18
|
+
throw argumentError('services list accepts no service selector.');
|
|
17
19
|
const inspection = inspectApplication(root);
|
|
18
20
|
const keys = [
|
|
19
21
|
...inspection.setupProviders.data
|
|
@@ -57,14 +59,14 @@ export async function runServiceCommand(root, input) {
|
|
|
57
59
|
}
|
|
58
60
|
const key = args.shift();
|
|
59
61
|
if (!key || key.startsWith('-') || key.length > 1024)
|
|
60
|
-
throw
|
|
62
|
+
throw argumentError('Choose the exact service key from services list.');
|
|
61
63
|
const options = {};
|
|
62
64
|
for (let i = 0; i < args.length; i += 2) {
|
|
63
65
|
if (!['--hours', '--table', '--offset', '--token', '--confirm-name', '--cursor'].includes(args[i]) ||
|
|
64
66
|
options[args[i]] !== undefined ||
|
|
65
67
|
!args[i + 1] ||
|
|
66
68
|
args[i + 1].startsWith('-'))
|
|
67
|
-
throw
|
|
69
|
+
throw argumentError('Invalid services options.');
|
|
68
70
|
options[args[i]] = args[i + 1];
|
|
69
71
|
}
|
|
70
72
|
const allowed = {
|
|
@@ -76,9 +78,9 @@ export async function runServiceCommand(root, input) {
|
|
|
76
78
|
delete: ['--token', '--confirm-name'],
|
|
77
79
|
};
|
|
78
80
|
if (Object.keys(options).some((option) => !allowed[action].includes(option)))
|
|
79
|
-
throw
|
|
81
|
+
throw argumentError('This services operation does not accept that option.');
|
|
80
82
|
if (action === 'delete' && (!options['--token'] || !options['--confirm-name']))
|
|
81
|
-
throw
|
|
83
|
+
throw argumentError('Deletion requires its plan token and exact resource name.');
|
|
82
84
|
const result = await serviceOperation(root, action, key, {
|
|
83
85
|
hours: options['--hours'] === undefined ? undefined : Number(options['--hours']),
|
|
84
86
|
table: options['--table'],
|
package/dist/ship.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare function shipCloudflareApplication(root: string, dryRun?: boolean
|
|
|
11
11
|
activated?: true | undefined;
|
|
12
12
|
nextAction?: string | undefined;
|
|
13
13
|
projectId: string;
|
|
14
|
-
release: import("./delivery.js").Release;
|
|
14
|
+
release: import("./delivery-evidence.js").Release;
|
|
15
15
|
managementFile: string;
|
|
16
16
|
productVerification: string;
|
|
17
17
|
} | ({
|
|
@@ -40,7 +40,7 @@ export declare function shipCloudflareApplication(root: string, dryRun?: boolean
|
|
|
40
40
|
}>;
|
|
41
41
|
export declare function shipSelectedVercelApplication(root: string, dryRun?: boolean, run?: DeliveryRunner, send?: typeof fetch, providerEnvironment?: NodeJS.ProcessEnv): Promise<{
|
|
42
42
|
projectId: string;
|
|
43
|
-
release: import("./vercel.js").WebRelease;
|
|
43
|
+
release: import("./vercel-project.js").WebRelease;
|
|
44
44
|
productVerification: string;
|
|
45
45
|
} | {
|
|
46
46
|
integrations: {
|
|
@@ -55,7 +55,7 @@ export declare function shipSelectedVercelApplication(root: string, dryRun?: boo
|
|
|
55
55
|
mutation: boolean;
|
|
56
56
|
};
|
|
57
57
|
mutation: boolean;
|
|
58
|
-
project: import("./vercel.js").WebProject;
|
|
58
|
+
project: import("./vercel-project.js").WebProject;
|
|
59
59
|
checks: string[];
|
|
60
60
|
deployment: string[];
|
|
61
61
|
cloudflareServices: string;
|
|
@@ -79,19 +79,19 @@ export declare function shipSelectedVercelApplication(root: string, dryRun?: boo
|
|
|
79
79
|
}>;
|
|
80
80
|
/** Each mixed target keeps its own release receipt; this is not a provider transaction. */
|
|
81
81
|
export declare function shipSelectedStack(root: string, dryRun?: boolean, run?: DeliveryRunner, request?: CloudflareRequest, send?: typeof fetch, providerEnvironment?: NodeJS.ProcessEnv): Promise<{
|
|
82
|
-
projectId: string;
|
|
83
|
-
release: import("./vercel.js").WebRelease;
|
|
84
|
-
productVerification: string;
|
|
85
|
-
} | {
|
|
86
82
|
management: string;
|
|
87
83
|
state?: "configuration-required" | undefined;
|
|
88
84
|
deployed?: false | undefined;
|
|
89
85
|
activated?: true | undefined;
|
|
90
86
|
nextAction?: string | undefined;
|
|
91
87
|
projectId: string;
|
|
92
|
-
release: import("./delivery.js").Release;
|
|
88
|
+
release: import("./delivery-evidence.js").Release;
|
|
93
89
|
managementFile: string;
|
|
94
90
|
productVerification: string;
|
|
91
|
+
} | {
|
|
92
|
+
projectId: string;
|
|
93
|
+
release: import("./vercel-project.js").WebRelease;
|
|
94
|
+
productVerification: string;
|
|
95
95
|
} | ({
|
|
96
96
|
project: import("./project-state.js").ApplicationProject;
|
|
97
97
|
checks: string[][];
|
|
@@ -124,7 +124,7 @@ export declare function shipSelectedStack(root: string, dryRun?: boolean, run?:
|
|
|
124
124
|
mutation: boolean;
|
|
125
125
|
};
|
|
126
126
|
mutation: boolean;
|
|
127
|
-
project: import("./vercel.js").WebProject;
|
|
127
|
+
project: import("./vercel-project.js").WebProject;
|
|
128
128
|
checks: string[];
|
|
129
129
|
deployment: string[];
|
|
130
130
|
cloudflareServices: string;
|
|
@@ -157,7 +157,7 @@ export declare function shipSelectedStack(root: string, dryRun?: boolean, run?:
|
|
|
157
157
|
activated?: true | undefined;
|
|
158
158
|
nextAction?: string | undefined;
|
|
159
159
|
projectId: string;
|
|
160
|
-
release: import("./delivery.js").Release;
|
|
160
|
+
release: import("./delivery-evidence.js").Release;
|
|
161
161
|
managementFile: string;
|
|
162
162
|
productVerification: string;
|
|
163
163
|
} | {
|
|
@@ -188,7 +188,7 @@ export declare function shipSelectedStack(root: string, dryRun?: boolean, run?:
|
|
|
188
188
|
activated?: true | undefined;
|
|
189
189
|
nextAction?: string | undefined;
|
|
190
190
|
projectId: string;
|
|
191
|
-
release: import("./delivery.js").Release;
|
|
191
|
+
release: import("./delivery-evidence.js").Release;
|
|
192
192
|
managementFile: string;
|
|
193
193
|
productVerification: string;
|
|
194
194
|
} | ({
|
|
@@ -219,7 +219,7 @@ export declare function shipSelectedStack(root: string, dryRun?: boolean, run?:
|
|
|
219
219
|
provider: string;
|
|
220
220
|
result: {
|
|
221
221
|
projectId: string;
|
|
222
|
-
release: import("./vercel.js").WebRelease;
|
|
222
|
+
release: import("./vercel-project.js").WebRelease;
|
|
223
223
|
productVerification: string;
|
|
224
224
|
} | {
|
|
225
225
|
integrations: {
|
|
@@ -234,7 +234,7 @@ export declare function shipSelectedStack(root: string, dryRun?: boolean, run?:
|
|
|
234
234
|
mutation: boolean;
|
|
235
235
|
};
|
|
236
236
|
mutation: boolean;
|
|
237
|
-
project: import("./vercel.js").WebProject;
|
|
237
|
+
project: import("./vercel-project.js").WebProject;
|
|
238
238
|
checks: string[];
|
|
239
239
|
deployment: string[];
|
|
240
240
|
cloudflareServices: string;
|
|
@@ -272,7 +272,7 @@ export declare function shipSelectedStack(root: string, dryRun?: boolean, run?:
|
|
|
272
272
|
activated?: true | undefined;
|
|
273
273
|
nextAction?: string | undefined;
|
|
274
274
|
projectId: string;
|
|
275
|
-
release: import("./delivery.js").Release;
|
|
275
|
+
release: import("./delivery-evidence.js").Release;
|
|
276
276
|
managementFile: string;
|
|
277
277
|
productVerification: string;
|
|
278
278
|
} | ({
|
|
@@ -327,7 +327,7 @@ export declare function shipSelectedStack(root: string, dryRun?: boolean, run?:
|
|
|
327
327
|
audience: "unconfigured" | "public" | "private";
|
|
328
328
|
provider: string;
|
|
329
329
|
} | {
|
|
330
|
-
project: import("./vercel.js").WebProject;
|
|
330
|
+
project: import("./vercel-project.js").WebProject;
|
|
331
331
|
checks: string[];
|
|
332
332
|
deployment: string[];
|
|
333
333
|
cloudflareServices: string;
|