@runeditrun/rer 0.2.12 → 0.2.14

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.
@@ -4,6 +4,7 @@ import { invalid, refuse, RerError } from './errors.mjs';
4
4
  import { ownerDeploy } from './deploy.mjs';
5
5
  import { deployEnvironment, deployAgain } from './deploy-inputs.mjs';
6
6
  import { claimHostedOwner } from './deploy-owner.mjs';
7
+ import { checkHostedSetup, hostedSetupFailure } from './deploy-setup.mjs';
7
8
  import { mutationReadinessFailure } from './deploy-readiness.mjs';
8
9
  import { observeOwner } from './deploy-observation.mjs';
9
10
  import { committedSource } from './deploy-source.mjs';
@@ -97,6 +98,8 @@ export async function deployCommand(context) {
97
98
  const kit = state ? { secret: (extra, values) => command('secret', extra, values), recordClaim: outcome => command('record-owner', ['--outcome', outcome]) } : { token: deployed.setupToken || undefined };
98
99
  claimed = await claimHostedOwner({ hook: adapter.hooks?.owner, setupManifest, declaration, deployed: { ...state, origin, owner: claimed, observedOwner: () => claims.at(-1)?.outcome }, env, supplied, ...kit, addSecret, beforeClaim: token => link(token, origin), store, signal: context.signal });
99
100
  if (!linked) await linkDependencies?.(origin);
101
+ step = 'verify hosted setup';
102
+ await checkHostedSetup({ origin, claimed: claimed ?? state?.ownerClaim?.outcome ?? claims.at(-1)?.outcome, signal: context.signal });
100
103
  if (claimed) store.report(`${claimed === 'claimed' ? 'Claimed the hosted owner' : 'The hosted owner was already claimed and was kept'}${state ? '; the one-time setup token was removed' : ''}. Sign in by email at ${origin}.`);
101
104
  const { setupToken: _, ...result } = deployed;
102
105
  return { ...result, ...(claimed ? { owner: claimed } : {}), dependenciesLinked: true };
@@ -109,6 +112,8 @@ export async function deployCommand(context) {
109
112
  const outcome = error.owner ?? claimed ?? observedClaims.at(-1)?.outcome;
110
113
  const state = deployed?.deployed || recorded ? `The application is deployed at ${deployed?.origin ?? recorded.origin}; ${outcome ? `owner ${outcome}` : 'owner claim is not confirmed'}${recorded ? '; setup token retirement is not confirmed' : ''}.` : 'The custom deploy did not finish; inspect its deployment record before recovery.';
111
114
  const redact = value => store.redact?.(redaction.redact(value)) ?? redaction.redact(value);
115
+ const setup = hostedSetupFailure(error, { origin: deployed?.origin ?? recorded?.origin, again });
116
+ if (setup) throw commandFailure(redact(setup));
112
117
  const readiness = mutationReadinessFailure(error, { again, redact });
113
118
  if (readiness) throw commandFailure(readiness);
114
119
  const refused = providerRefusal(error);
@@ -0,0 +1,25 @@
1
+ // Some native apps expose setup status without registering a shared owner step.
2
+ // An explicit unfinished setup must not become deploy success just because
3
+ // /health is healthy. An absent or unsupported endpoint proves nothing either
4
+ // way and remains compatible with apps that do not implement this optional API.
5
+ export async function checkHostedSetup({ origin, claimed, signal }) {
6
+ if (['claimed', 'kept'].includes(claimed)) return;
7
+ let required = false;
8
+ try {
9
+ const response = await globalThis.fetch(new URL('/api/identity/setup-status', origin), {
10
+ method: 'GET', credentials: 'omit', redirect: 'manual',
11
+ headers: { Accept: 'application/json', 'Cache-Control': 'no-cache' },
12
+ signal: signal ? AbortSignal.any([signal, AbortSignal.timeout(10000)]) : AbortSignal.timeout(10000),
13
+ });
14
+ // Never follow a redirect or interpret an error page as a setup contract.
15
+ if (!response.redirected && (response.ok || response.status === 409)) required = (await response.json())?.setupRequired === true;
16
+ else await response.body?.cancel();
17
+ } catch { /* Only an explicit setup-required response establishes this gap. */ }
18
+ signal?.throwIfAborted();
19
+ if (required) throw new Error('hosted-setup-required');
20
+ }
21
+
22
+ export function hostedSetupFailure(error, { origin, again }) {
23
+ if (error.message !== 'hosted-setup-required') return undefined;
24
+ return `Deploy is incomplete. The application is deployed at ${origin}, but /api/identity/setup-status reports that setup is required and the owner claim is not confirmed. The deployed resources are retained for recovery. Fix or register the application's actual native owner-claim integration in its adapter and setup manifest, then rerun ${again} using the same environment credentials.`;
25
+ }
package/cli/deploy.mjs CHANGED
@@ -8,6 +8,7 @@ import { packageBuild } from '../modules/deploy-kit/prepare.mjs';
8
8
  import { refuseLocalModels } from '../modules/deploy-kit/local-only.mjs';
9
9
  import { deployEnvironment, deployAgain } from './deploy-inputs.mjs';
10
10
  import { claimHostedOwner } from './deploy-owner.mjs';
11
+ import { checkHostedSetup, hostedSetupFailure } from './deploy-setup.mjs';
11
12
  import { mutationReadinessFailure } from './deploy-readiness.mjs';
12
13
  import { committedSource } from './deploy-source.mjs';
13
14
  import { hookState, forgetHookState } from './deploy-hook-record.mjs';
@@ -79,7 +80,6 @@ export function ownerDeploy(declarationPath, lifecycle) {
79
80
  if (sent.length) store.report(`rer supplied ${sent.join(', ')} from the local setup owner and fresh generated values.`);
80
81
  step = 'health';
81
82
  await owner('health');
82
- store.report(`Your application is live on your Cloudflare account at ${deployed.origin}.`);
83
83
  step = 'claim owner';
84
84
  const { liveSecrets, retiredSecrets, ownerClaim } = await owner('inspect');
85
85
  const linked = token => linkDependencies?.(deployed.origin, token);
@@ -87,6 +87,9 @@ export function ownerDeploy(declarationPath, lifecycle) {
87
87
  secret: (extra, values) => owner('secret', extra, values), beforeClaim: linked, recordClaim: outcome => owner('record-owner', ['--outcome', outcome]), inspect: () => owner('inspect'), store, signal });
88
88
  // A seed that claims its owner its own way links with the token it was given.
89
89
  if (claimed === undefined) await linked(env[declared(claim?.tokenField ?? 'SETUP_TOKEN')?.environment]);
90
+ step = 'verify hosted setup';
91
+ await checkHostedSetup({ origin: deployed.origin, claimed: claimed ?? ownerClaim?.outcome, signal });
92
+ store.report(`Your application is live on your Cloudflare account at ${deployed.origin}.`);
90
93
  // The app claims the OWNER_EMAIL the Worker holds: the local one only when this run uploaded it.
91
94
  const email = declared(claim?.emailField);
92
95
  const named = !email ? '' : deployed.sentSecrets.includes(email.binding) && env[email.environment] ? ` (${env[email.environment]})` : ` (the ${email.binding} already set on the Worker)`;
@@ -102,6 +105,8 @@ export function ownerDeploy(declarationPath, lifecycle) {
102
105
 
103
106
  // The failing step, its redacted cause, what this run created and the command that continues.
104
107
  function failureText({ error, step, created, again, retry, secretChange, deployed, redact }) {
108
+ const setup = hostedSetupFailure(error, { origin: deployed?.origin, again });
109
+ if (setup) return redact(setup);
105
110
  const readiness = mutationReadinessFailure(error, { again, redact });
106
111
  if (readiness) return readiness;
107
112
  const diagnostic = deployDiagnostic(error, redact);
@@ -1,5 +1,24 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.14
4
+
5
+ - Workerd container and hosted demo builds admit native `cloudflare:workers` imports, Durable Object definitions, `WebSocketPair`, `crypto.subtle.timingSafeEqual` and `ctx.passThroughOnException`. Node-engine restrictions are unchanged.
6
+ - Container packaging requires configured Durable Objects to be local and exported by the built Worker. External namespace bindings and missing exports fail before packaging. Raw sockets and the existing container isolation restrictions remain refused.
7
+
8
+ ### Upgrade notes
9
+
10
+ - Update rer and rebuild the demo image to receive the workerd admission fix. Durable Object namespaces still need local Wrangler bindings and exported classes. Allowing `WebSocketPair` does not add WebSocket upgrade handling to the container HTTP host.
11
+
12
+ ## 0.2.13
13
+
14
+ - `rer deploy --remove` accepts empty owned R2 object listings without pagination metadata, fixing the 0.2.9 regression. Populated or malformed listings still require complete pagination proof before deletion.
15
+ - Workerd container images may use `HTMLRewriter`, including hosted demo images. Engines without that API still refuse it.
16
+ - A deploy whose hosted app explicitly reports setup required without a confirmed owner claim exits 1 with the recovery step. The live announcement follows owner handling and the setup check.
17
+
18
+ ### Upgrade notes
19
+
20
+ - Update the rer package to receive these deploy fixes. An app with an unregistered native owner claim still needs that integration repaired; rer now reports the incomplete deployment and retains its resources for recovery.
21
+
3
22
  ## 0.2.12
4
23
 
5
24
  - Import-kit resumable field redaction finishes however large one import job is. A step takes as many jobs as fit the request (at most 25); a job that does not fit alone is redacted in pages of its entries, and a step that would not fit writes nothing and is retried smaller, so every committed step stays inside D1's per-request limit and the erasure reaches its final batch. Receipts and match counts are unchanged.
@@ -12,11 +12,37 @@ at the intended memory limit. A retained-public-snapshot cache contract is
12
12
  selected through `cacheContract` when the seed implements that contract. This
13
13
  is not a general Durable Object adapter. A seed requiring KV or other
14
14
  Cloudflare-only APIs cannot use Node.
15
- The import boundary rejects those APIs and new Cloudflare imports outside the
15
+ For Node, the import boundary rejects those APIs and new Cloudflare imports outside the
16
16
  platform binding/cache boundary. The one other file it admits is an exported
17
17
  seed's demo guard, `src/modules/demo/index.mjs`, and there only
18
18
  `import { env } from 'cloudflare:workers'` (it reads `RER_DEMO`).
19
19
 
20
+ The workerd engine admits exact `cloudflare:workers` static imports, literal
21
+ dynamic imports and re-exports, plus `HTMLRewriter`, `WebSocketPair`,
22
+ `crypto.subtle.timingSafeEqual` and `ctx.passThroughOnException`. Other
23
+ `cloudflare:` modules (including sockets), `require()` or arbitrary calls with
24
+ Cloudflare module strings, `email()`, `caches.default` and `request.cf` remain
25
+ outside the container boundary.
26
+ Other Cloudflare modules have no admitted host adapters; raw sockets would also
27
+ bypass the host's routed fetch egress. Native `email()` has no configured host
28
+ delivery, `caches.default` has no declared container cache contract, and the host
29
+ disables request CF metadata (`cf: false`). The module import rule admits native
30
+ ES module loading, not arbitrary calls carrying module strings. Admitting
31
+ `WebSocketPair` does not add HTTP upgrade transport or qualify a complete live
32
+ WebSocket flow through the container host.
33
+
34
+ The workerd source boundary permits Durable Object definitions, including export
35
+ aliases and indirect inheritance. Unbound definitions create no namespace. The
36
+ seed's Vite build selects and renders its configuration; before packaging, the
37
+ container builder checks each namespace in the emitted
38
+ `dist/server/wrangler.json`. It rejects `script_name` and `environment`, because
39
+ the host binds only local namespaces, and requires each configured class name in
40
+ the bundler's exports for the emitted Worker entry. This validates the binding
41
+ contract without inferring source class names. Workerd readiness alone does not
42
+ reject a missing class export; actual class behavior still needs runtime
43
+ qualification. Node's binding, retained-cache and demo-guard exceptions are
44
+ unchanged.
45
+
20
46
  The entrypoint holds a Linux kernel `flock` for the lifetime of the host. Each
21
47
  installation has one local data volume and one writer. The lock inode retains
22
48
  PID/heartbeat diagnostics and is never unlinked. The host applies hashed
@@ -21,15 +21,15 @@ export async function checkBoundary(root, { engine='node', cacheContract }={}) {
21
21
  if(module.startsWith('cloudflare:')){
22
22
  const imports=node.importClause?.namedBindings;
23
23
  const allowed=module==='cloudflare:workers'&&imports&&ts.isNamedImports(imports)&&imports.elements.every(element=>(demo&&!node.importClause.name&&!element.propertyName&&element.name.text==='env')||(bindings&&(element.propertyName??element.name).text==='env')||(cache&&(element.propertyName??element.name).text==='DurableObject'));
24
- if(!allowed)fail('Cloudflare import outside binding/cache contract');
24
+ if(!allowed&&!(engine==='workerd'&&module==='cloudflare:workers'))fail('Cloudflare import outside binding/cache contract');
25
25
  }
26
26
  }
27
- if(ts.isCallExpression(node)&&node.arguments.some(arg=>ts.isStringLiteral(arg)&&arg.text.startsWith('cloudflare:')))fail('Dynamic Cloudflare import');
28
- if(ts.isIdentifier(node)&&['WebSocketPair','HTMLRewriter','passThroughOnException','timingSafeEqual'].includes(node.text))fail(node.text);
27
+ if(ts.isCallExpression(node)&&node.arguments.some((arg,index)=>ts.isStringLiteral(arg)&&arg.text.startsWith('cloudflare:')&&!(engine==='workerd'&&node.expression.kind===ts.SyntaxKind.ImportKeyword&&index===0&&arg.text==='cloudflare:workers')))fail('Dynamic Cloudflare import');
28
+ if(ts.isIdentifier(node)&&engine!=='workerd'&&['WebSocketPair','passThroughOnException','timingSafeEqual','HTMLRewriter'].includes(node.text))fail(node.text);
29
29
  if(ts.isCallExpression(node)&&ts.isIdentifier(node.expression)&&node.expression.text==='email'&&!localNames.has('email'))fail('email()');
30
30
  if(ts.isPropertyAccessExpression(node)&&((node.expression.getText(tree)==='caches'&&node.name.text==='default')||(node.expression.getText(tree)==='request'&&node.name.text==='cf')))fail(node.getText(tree));
31
31
  if(ts.isElementAccessExpression(node)&&ts.isStringLiteral(node.argumentExpression)&&((node.expression.getText(tree)==='caches'&&node.argumentExpression.text==='default')||(node.expression.getText(tree)==='request'&&node.argumentExpression.text==='cf')))fail(node.getText(tree));
32
- if(ts.isHeritageClause(node)&&node.token===ts.SyntaxKind.ExtendsKeyword&&node.types.some(type=>/DurableObject/.test(type.expression.getText(tree)))&&!cache)fail('New Durable Object');
32
+ if(engine!=='workerd'&&ts.isHeritageClause(node)&&node.token===ts.SyntaxKind.ExtendsKeyword&&node.types.some(type=>/DurableObject/.test(type.expression.getText(tree)))&&!cache)fail('New Durable Object');
33
33
  ts.forEachChild(node,visit);
34
34
  }
35
35
  visit(tree);
@@ -1,11 +1,12 @@
1
- import { readFile, writeFile, readdir, cp, mkdir, rm } from 'node:fs/promises';
2
- import { join, resolve } from 'node:path';
1
+ import { readFile, writeFile, readdir, realpath, cp, mkdir, rm } from 'node:fs/promises';
2
+ import { dirname, join, resolve } from 'node:path';
3
3
  import { createRequire } from 'node:module';
4
4
  import { pathToFileURL } from 'node:url';
5
5
  import { createHash } from 'node:crypto';
6
6
  import { parseJsonc } from '../../cli/jsonc.mjs';
7
7
  import { portabilityPlan } from './portability-schema.mjs';
8
8
  import { checkBoundary } from './boundary.mjs';
9
+ import { localDurableObjects } from './durable-objects.mjs';
9
10
  import { readMigrationRewrites, withRewrites } from '../deploy-kit/migrations.mjs';
10
11
  const hash = source => createHash('sha256').update(source).digest('hex');
11
12
  export async function buildContainer(root, options={}) {
@@ -21,6 +22,13 @@ async function buildImage(root, { output = join(root,'.rer/container/image'), en
21
22
  const vite = await import(pathToFileURL(require.resolve('vite'))), loaded = await vite.loadConfigFromFile({ command:'build',mode:'production' },undefined,root);
22
23
  if (!loaded) throw new Error('Vite configuration missing');
23
24
  const config = loaded.config;
25
+ const outputExports = new Map();
26
+ if (engine === 'workerd') config.plugins = [...(config.plugins ?? []), {
27
+ name:'rer-container-exports',
28
+ async writeBundle(output,bundle) {
29
+ for (const chunk of Object.values(bundle)) if (chunk.type === 'chunk' && chunk.isEntry) outputExports.set(await realpath(resolve(root,output.dir ?? dirname(output.file),chunk.fileName)),new Set(chunk.exports));
30
+ },
31
+ }];
24
32
  if (engine === 'node') {
25
33
  const plugins = (await Promise.all(config.plugins.flat(Infinity))).filter(plugin => plugin && !plugin.name.startsWith('vite-plugin-cloudflare') && plugin.name !== 'tanstack-start-core:post-build');
26
34
  const bindingShim = resolve(import.meta.dirname,'bindings.mjs');
@@ -34,7 +42,10 @@ async function buildImage(root, { output = join(root,'.rer/container/image'), en
34
42
  // Apply the same local-only bundle guard before packaging any container image.
35
43
  await (await import('../../cli/dev-identity.mjs')).refuseDevLayerOutput(root);
36
44
  let workerConfig;
37
- if (engine === 'workerd') workerConfig = JSON.parse(await readFile(join(root,'dist/server/wrangler.json'),'utf8'));
45
+ if (engine === 'workerd') {
46
+ workerConfig = JSON.parse(await readFile(join(root,'dist/server/wrangler.json'),'utf8'));
47
+ localDurableObjects(workerConfig,outputExports.get(await realpath(resolve(root,'dist/server',workerConfig.main))));
48
+ }
38
49
  else workerConfig = parseJsonc(await readFile(join(root,'wrangler.jsonc'),'utf8'));
39
50
  const { unstable_splitSqlQuery:split } = require('wrangler');
40
51
  const migrations = {}, rewrites = await readMigrationRewrites(root);
@@ -0,0 +1,15 @@
1
+ // worker-engine binds every namespace to a class in this Worker. Never silently
2
+ // reinterpret a cross-worker namespace as a local one. Check the bundler's actual
3
+ // entry exports: workerd readiness alone does not reject missing class exports.
4
+ export function localDurableObjects(config, exports) {
5
+ const bindings=config.durable_objects?.bindings??[];
6
+ if(!Array.isArray(bindings))throw new Error('Container Durable Object bindings must be an array');
7
+ for(const binding of bindings) {
8
+ if(!binding||typeof binding.name!=='string'||!binding.name||typeof binding.class_name!=='string'||!binding.class_name)throw new Error('Container Durable Object binding requires name and class_name');
9
+ if(Object.hasOwn(binding,'script_name')||Object.hasOwn(binding,'environment'))throw new Error('Container Durable Object bindings do not support script_name or environment');
10
+ }
11
+ const classes=new Set(bindings.map(binding=>binding.class_name));
12
+ if(classes.size&&!exports)throw new Error('Built container Worker entry exports are unavailable');
13
+ for(const name of classes)if(!exports.has(name))throw new Error('Built container Worker does not export configured Durable Object class: '+name);
14
+ return classes;
15
+ }
@@ -22,6 +22,9 @@ export async function* r2ObjectPages(api, bucket) {
22
22
  const data = await api.envelope(`/r2/buckets/${bucket}/objects?per_page=1000${cursor ? `&cursor=${encodeURIComponent(cursor)}` : ''}`);
23
23
  const rows = data.result, info = data.result_info;
24
24
  assert(Array.isArray(rows) && rows.length <= 1000 && rows.every(row => typeof row?.key === 'string' && row.key.length), 'invalid-r2-object-list');
25
+ // Empty object listings may omit pagination or return null. Only that
26
+ // shape proves completion without explicit pagination evidence.
27
+ if (rows.length === 0 && info == null) { yield rows; return; }
25
28
  assert(info && typeof info.is_truncated === 'boolean' && (!info.delimited || Array.isArray(info.delimited) && !info.delimited.length), 'provider-incomplete-pagination');
26
29
  assert(new Set(rows.map(row => row.key)).size === rows.length, 'invalid-r2-object-list');
27
30
  if (info.is_truncated) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runeditrun/rer",
3
- "version": "0.2.12",
3
+ "version": "0.2.14",
4
4
  "description": "The rer command: install, set up, run and launch Run Edit Run checkouts.",
5
5
  "license": "MIT",
6
6
  "type": "module",