rebilder 0.2.0 → 0.3.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/CHANGELOG.md +32 -0
- package/README.md +81 -62
- package/dist/bin.js +424 -134
- package/dist/bin.js.map +1 -1
- package/dist/index.d.ts +16 -21
- package/dist/index.js +424 -134
- package/dist/index.js.map +1 -1
- package/package.json +12 -7
- package/dist/index.cjs +0 -1633
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts +0 -503
package/dist/index.js
CHANGED
|
@@ -337,66 +337,113 @@ function approxTokensOf(capture) {
|
|
|
337
337
|
}
|
|
338
338
|
|
|
339
339
|
// src/commands/init.ts
|
|
340
|
-
var FRAMEWORKS = [
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
340
|
+
var FRAMEWORKS = [
|
|
341
|
+
"next",
|
|
342
|
+
"node",
|
|
343
|
+
"edge",
|
|
344
|
+
"shopify",
|
|
345
|
+
"fetch",
|
|
346
|
+
"sveltekit",
|
|
347
|
+
"nuxt",
|
|
348
|
+
"astro",
|
|
349
|
+
"react-router",
|
|
350
|
+
"remix",
|
|
351
|
+
"hono",
|
|
352
|
+
"bun",
|
|
353
|
+
"deno",
|
|
354
|
+
"netlify",
|
|
355
|
+
"vercel"
|
|
356
|
+
];
|
|
357
|
+
var FRAMEWORK_FILES = [
|
|
358
|
+
{ file: "shopify.app.toml", framework: "shopify" },
|
|
359
|
+
{ file: "next.config.ts", framework: "next" },
|
|
360
|
+
{ file: "next.config.mjs", framework: "next" },
|
|
361
|
+
{ file: "next.config.js", framework: "next" },
|
|
362
|
+
{ file: "svelte.config.js", framework: "sveltekit" },
|
|
363
|
+
{ file: "svelte.config.ts", framework: "sveltekit" },
|
|
364
|
+
{ file: "nuxt.config.ts", framework: "nuxt" },
|
|
365
|
+
{ file: "nuxt.config.js", framework: "nuxt" },
|
|
366
|
+
{ file: "nuxt.config.mjs", framework: "nuxt" },
|
|
367
|
+
{ file: "astro.config.mjs", framework: "astro" },
|
|
368
|
+
{ file: "astro.config.ts", framework: "astro" },
|
|
369
|
+
{ file: "astro.config.js", framework: "astro" },
|
|
370
|
+
{ file: "react-router.config.ts", framework: "react-router" },
|
|
371
|
+
{ file: "react-router.config.js", framework: "react-router" },
|
|
372
|
+
{ file: "remix.config.js", framework: "remix" }
|
|
356
373
|
];
|
|
357
|
-
var
|
|
374
|
+
var FRAMEWORK_DEPENDENCIES = [
|
|
358
375
|
{ dependency: "@shopify/shopify-app-remix", framework: "shopify" },
|
|
376
|
+
{ dependency: "@shopify/shopify-app-react-router", framework: "shopify" },
|
|
359
377
|
{ dependency: "@shopify/shopify-api", framework: "shopify" },
|
|
360
378
|
{ dependency: "next", framework: "next" },
|
|
361
|
-
{ dependency: "@
|
|
362
|
-
{ dependency: "
|
|
363
|
-
{ dependency: "
|
|
379
|
+
{ dependency: "@sveltejs/kit", framework: "sveltekit" },
|
|
380
|
+
{ dependency: "nuxt", framework: "nuxt" },
|
|
381
|
+
{ dependency: "astro", framework: "astro" },
|
|
382
|
+
{ dependency: "@react-router/dev", framework: "react-router" },
|
|
383
|
+
{ dependency: "@react-router/node", framework: "react-router" },
|
|
384
|
+
{ dependency: "@remix-run/node", framework: "remix" },
|
|
385
|
+
{ dependency: "@remix-run/express", framework: "remix" },
|
|
386
|
+
{ dependency: "hono", framework: "hono" },
|
|
364
387
|
{ dependency: "express", framework: "node" },
|
|
365
388
|
{ dependency: "fastify", framework: "node" }
|
|
366
389
|
];
|
|
367
|
-
|
|
368
|
-
|
|
390
|
+
var RUNTIME_FILES = [
|
|
391
|
+
{ file: "wrangler.toml", framework: "edge" },
|
|
392
|
+
{ file: "wrangler.jsonc", framework: "edge" },
|
|
393
|
+
{ file: "wrangler.json", framework: "edge" },
|
|
394
|
+
{ file: "netlify.toml", framework: "netlify" },
|
|
395
|
+
{ file: "vercel.json", framework: "vercel" },
|
|
396
|
+
{ file: "deno.json", framework: "deno" },
|
|
397
|
+
{ file: "deno.jsonc", framework: "deno" },
|
|
398
|
+
{ file: "bunfig.toml", framework: "bun" },
|
|
399
|
+
{ file: "bun.lock", framework: "bun" },
|
|
400
|
+
{ file: "bun.lockb", framework: "bun" }
|
|
401
|
+
];
|
|
402
|
+
var RUNTIME_DEPENDENCIES = [
|
|
403
|
+
{ dependency: "wrangler", framework: "edge" },
|
|
404
|
+
{ dependency: "@cloudflare/workers-types", framework: "edge" },
|
|
405
|
+
{ dependency: "@netlify/edge-functions", framework: "netlify" },
|
|
406
|
+
{ dependency: "@vercel/functions", framework: "vercel" }
|
|
407
|
+
];
|
|
408
|
+
async function firstFile(runtime, markers) {
|
|
409
|
+
for (const marker of markers) {
|
|
369
410
|
if (await runtime.readFile(marker.file) !== null) {
|
|
370
|
-
return {
|
|
411
|
+
return {
|
|
412
|
+
framework: marker.framework,
|
|
413
|
+
reason: `detected from ${marker.file} in the working directory`
|
|
414
|
+
};
|
|
371
415
|
}
|
|
372
416
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
...asRecord(record["devDependencies"])
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
} catch {
|
|
386
|
-
dependencies = {};
|
|
387
|
-
}
|
|
388
|
-
for (const marker of DEPENDENCY_MARKERS) {
|
|
389
|
-
if (marker.dependency in dependencies) {
|
|
390
|
-
return {
|
|
391
|
-
framework: marker.framework,
|
|
392
|
-
reason: `detected from "${marker.dependency}" in package.json`
|
|
393
|
-
};
|
|
394
|
-
}
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
function firstDependency(dependencies, markers) {
|
|
420
|
+
for (const marker of markers) {
|
|
421
|
+
if (marker.dependency in dependencies) {
|
|
422
|
+
return {
|
|
423
|
+
framework: marker.framework,
|
|
424
|
+
reason: `detected from "${marker.dependency}" in package.json`
|
|
425
|
+
};
|
|
395
426
|
}
|
|
396
427
|
}
|
|
397
|
-
return
|
|
398
|
-
|
|
399
|
-
|
|
428
|
+
return null;
|
|
429
|
+
}
|
|
430
|
+
async function readDependencies(runtime) {
|
|
431
|
+
const manifest = await runtime.readFile("package.json");
|
|
432
|
+
if (manifest === null) return {};
|
|
433
|
+
try {
|
|
434
|
+
const parsed = JSON.parse(manifest);
|
|
435
|
+
if (typeof parsed !== "object" || parsed === null) return {};
|
|
436
|
+
const record = parsed;
|
|
437
|
+
return { ...asRecord(record["dependencies"]), ...asRecord(record["devDependencies"]) };
|
|
438
|
+
} catch {
|
|
439
|
+
return {};
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
async function detectFramework(runtime) {
|
|
443
|
+
const dependencies = await readDependencies(runtime);
|
|
444
|
+
return await firstFile(runtime, FRAMEWORK_FILES) ?? firstDependency(dependencies, FRAMEWORK_DEPENDENCIES) ?? await firstFile(runtime, RUNTIME_FILES) ?? firstDependency(dependencies, RUNTIME_DEPENDENCIES) ?? {
|
|
445
|
+
framework: "fetch",
|
|
446
|
+
reason: `no framework marker found \u2014 scaffolding the framework-neutral fetch middleware. Pass --framework ${FRAMEWORKS.join("|")} to choose.`
|
|
400
447
|
};
|
|
401
448
|
}
|
|
402
449
|
function asRecord(value) {
|
|
@@ -423,7 +470,7 @@ async function runInit(command, runtime) {
|
|
|
423
470
|
}
|
|
424
471
|
var SHARED_NOTES = [
|
|
425
472
|
"The resolvers return your source of truth. Every substantive value \u2014 price, stock, hours, policy text \u2014 comes from these fields; the gateway never invents one.",
|
|
426
|
-
"The
|
|
473
|
+
"The Apache-2.0 SDK serves without a Rebilder account or subscription. Configure reporting separately.",
|
|
427
474
|
"Run `rebilder check <url>` before and after to see what changed. Content negotiation is D2.1 (10 points) and unlocks D2.3 and D2.4."
|
|
428
475
|
];
|
|
429
476
|
var CONFIG_BODY = `import type { GatewayConfig } from '@rebilder/gateway'
|
|
@@ -449,81 +496,287 @@ export const gatewayConfig: GatewayConfig = {
|
|
|
449
496
|
// onEvent: (event) => { void event },
|
|
450
497
|
}
|
|
451
498
|
`;
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
499
|
+
function scaffold(suggestedPath, mount, notes) {
|
|
500
|
+
const [header = "", ...body] = mount.trim().split("\n");
|
|
501
|
+
const commented = body.map((line) => line === "" ? "//" : `// ${line}`);
|
|
502
|
+
return {
|
|
503
|
+
suggestedPath,
|
|
455
504
|
language: "ts",
|
|
456
|
-
notes: [
|
|
457
|
-
"Then add the proxy: `const gateway = createGatewayProxy(gatewayConfig)` in proxy.ts (Next 16) or middleware.ts (Next 15 and earlier), returning `(await gateway(req)) ?? NextResponse.next()`.",
|
|
458
|
-
...SHARED_NOTES
|
|
459
|
-
],
|
|
505
|
+
notes: [...notes, ...SHARED_NOTES],
|
|
460
506
|
contents: `${CONFIG_BODY}
|
|
461
|
-
|
|
462
|
-
//
|
|
463
|
-
// import { NextResponse } from 'next/server'
|
|
464
|
-
// import { createGatewayProxy } from '@rebilder/gateway/next'
|
|
465
|
-
// import { gatewayConfig } from './lib/gateway-config'
|
|
507
|
+
${header}
|
|
466
508
|
//
|
|
467
|
-
|
|
468
|
-
//
|
|
469
|
-
// export default async function proxy(req: Request) {
|
|
470
|
-
// return (await gateway(req)) ?? NextResponse.next()
|
|
471
|
-
// }
|
|
509
|
+
${commented.join("\n")}
|
|
472
510
|
`
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
var DOCS = "https://rebilder.com/docs/adapters";
|
|
514
|
+
var SCAFFOLDS = {
|
|
515
|
+
next: scaffold(
|
|
516
|
+
"lib/gateway-config.ts",
|
|
517
|
+
`
|
|
518
|
+
/* \u2500\u2500 proxy.ts (Next 16) or middleware.ts (Next \u226415) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
519
|
+
import { NextResponse } from 'next/server'
|
|
520
|
+
import { createGatewayProxy } from '@rebilder/gateway/next'
|
|
521
|
+
import { gatewayConfig } from './lib/gateway-config'
|
|
522
|
+
|
|
523
|
+
// Passing the fallthrough adds Vary: Accept to your HTML responses too.
|
|
524
|
+
export default createGatewayProxy(gatewayConfig, () => NextResponse.next())
|
|
525
|
+
`,
|
|
526
|
+
[
|
|
527
|
+
"Then add the proxy: `createGatewayProxy(gatewayConfig, () => NextResponse.next())` in proxy.ts (Next 16) or middleware.ts (Next 15 and earlier).",
|
|
528
|
+
`Full guide: ${DOCS}/nextjs`
|
|
529
|
+
]
|
|
530
|
+
),
|
|
531
|
+
node: scaffold(
|
|
532
|
+
"gateway-config.ts",
|
|
533
|
+
`
|
|
482
534
|
/* \u2500\u2500 Express \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
//
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
535
|
+
import express from 'express'
|
|
536
|
+
import { createGatewayMiddleware } from '@rebilder/gateway/node'
|
|
537
|
+
import { gatewayConfig } from './gateway-config'
|
|
538
|
+
|
|
539
|
+
const app = express()
|
|
540
|
+
app.use(createGatewayMiddleware(gatewayConfig)) // before your routes
|
|
541
|
+
`,
|
|
542
|
+
[
|
|
543
|
+
"Then mount it before your routes: `app.use(createGatewayMiddleware(gatewayConfig))`.",
|
|
544
|
+
`Fastify and the full guide: ${DOCS}/node`
|
|
545
|
+
]
|
|
546
|
+
),
|
|
547
|
+
edge: scaffold(
|
|
548
|
+
"gateway-config.ts",
|
|
549
|
+
`
|
|
550
|
+
/* \u2500\u2500 worker.ts (Cloudflare Workers) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
551
|
+
import { createGatewayFetchHandler } from '@rebilder/gateway/edge'
|
|
552
|
+
import { gatewayConfig } from './gateway-config'
|
|
553
|
+
|
|
554
|
+
export default { fetch: createGatewayFetchHandler(gatewayConfig) }
|
|
555
|
+
`,
|
|
556
|
+
[
|
|
496
557
|
"Then export the fetch handler: `export default { fetch: createGatewayFetchHandler(gatewayConfig) }`.",
|
|
497
558
|
"On a route-mounted Worker, non-markdown requests pass through to your origin unchanged, so browsers and crawlers keep receiving the canonical HTML.",
|
|
498
|
-
|
|
499
|
-
]
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
// import { gatewayConfig } from './gateway-config'
|
|
505
|
-
//
|
|
506
|
-
// export default { fetch: createGatewayFetchHandler(gatewayConfig) }
|
|
507
|
-
`
|
|
508
|
-
},
|
|
509
|
-
shopify: {
|
|
510
|
-
suggestedPath: "app/gateway-config.ts",
|
|
511
|
-
language: "ts",
|
|
512
|
-
notes: [
|
|
513
|
-
"Then mount the app-proxy handler and give it your app\u2019s shared secret; requests are signature-verified before anything is rendered.",
|
|
514
|
-
...SHARED_NOTES
|
|
515
|
-
],
|
|
516
|
-
contents: `${CONFIG_BODY}
|
|
559
|
+
`Full guide: ${DOCS}/cloudflare`
|
|
560
|
+
]
|
|
561
|
+
),
|
|
562
|
+
shopify: scaffold(
|
|
563
|
+
"app/gateway-config.ts",
|
|
564
|
+
`
|
|
517
565
|
/* \u2500\u2500 Shopify app proxy \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
566
|
+
import { createShopifyAppProxyHandler } from '@rebilder/gateway/shopify'
|
|
567
|
+
import { gatewayConfig } from './gateway-config'
|
|
568
|
+
|
|
569
|
+
export const loader = createShopifyAppProxyHandler(gatewayConfig, {
|
|
570
|
+
sharedSecret: process.env.SHOPIFY_API_SECRET ?? '',
|
|
571
|
+
})
|
|
572
|
+
`,
|
|
573
|
+
[
|
|
574
|
+
"Then mount the app-proxy handler and give it your app\u2019s shared secret; requests are signature-verified before anything is rendered.",
|
|
575
|
+
`Full guide: ${DOCS}/shopify`
|
|
576
|
+
]
|
|
577
|
+
),
|
|
578
|
+
fetch: scaffold(
|
|
579
|
+
"gateway-config.ts",
|
|
580
|
+
`
|
|
581
|
+
/* \u2500\u2500 Any host whose middleware receives a Request and a next() \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
582
|
+
import { createFetchMiddleware } from '@rebilder/gateway/fetch'
|
|
583
|
+
import { gatewayConfig } from './gateway-config'
|
|
584
|
+
|
|
585
|
+
const gateway = createFetchMiddleware(gatewayConfig)
|
|
586
|
+
|
|
587
|
+
// In your middleware: return gateway(request, () => next())
|
|
588
|
+
`,
|
|
589
|
+
[
|
|
590
|
+
"Mount `createFetchMiddleware(gatewayConfig)` wherever your framework hands middleware a Request and a next().",
|
|
591
|
+
`Recipes for SvelteKit, Nuxt, Astro, React Router, Remix and Hono: ${DOCS}/frameworks`
|
|
592
|
+
]
|
|
593
|
+
),
|
|
594
|
+
sveltekit: scaffold(
|
|
595
|
+
"src/lib/gateway-config.ts",
|
|
596
|
+
`
|
|
597
|
+
/* \u2500\u2500 src/hooks.server.ts \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
598
|
+
import type { Handle } from '@sveltejs/kit'
|
|
599
|
+
import { createFetchMiddleware } from '@rebilder/gateway/fetch'
|
|
600
|
+
import { gatewayConfig } from '$lib/gateway-config'
|
|
601
|
+
|
|
602
|
+
const gateway = createFetchMiddleware(gatewayConfig)
|
|
603
|
+
|
|
604
|
+
export const handle: Handle = ({ event, resolve }) => gateway(event.request, () => resolve(event))
|
|
605
|
+
`,
|
|
606
|
+
[
|
|
607
|
+
"Then add the `handle` hook in src/hooks.server.ts. If you already have one, combine them with `sequence` from @sveltejs/kit/hooks.",
|
|
608
|
+
`Full guide: ${DOCS}/frameworks#sveltekit`
|
|
609
|
+
]
|
|
610
|
+
),
|
|
611
|
+
nuxt: scaffold(
|
|
612
|
+
"server/utils/gateway-config.ts",
|
|
613
|
+
`
|
|
614
|
+
/* \u2500\u2500 server/middleware/rebilder.ts (Nuxt and Nitro; h3 helpers are auto-imported) \u2500\u2500 */
|
|
615
|
+
import { handleRequest, negotiationHeaders } from '@rebilder/gateway/fetch'
|
|
616
|
+
import { gatewayConfig } from '../utils/gateway-config'
|
|
617
|
+
|
|
618
|
+
export default defineEventHandler(async (event) => {
|
|
619
|
+
if (event.method !== 'GET' && event.method !== 'HEAD') return
|
|
620
|
+
const served = await handleRequest(toWebRequest(event), gatewayConfig)
|
|
621
|
+
if (served) return served
|
|
622
|
+
for (const [name, value] of negotiationHeaders(gatewayConfig, getRequestURL(event))) {
|
|
623
|
+
appendResponseHeader(event, name, value)
|
|
526
624
|
}
|
|
625
|
+
})
|
|
626
|
+
`,
|
|
627
|
+
[
|
|
628
|
+
"Then add the server middleware. It returns markdown to agents and otherwise returns nothing, so Nuxt renders the page as usual.",
|
|
629
|
+
`Full guide: ${DOCS}/frameworks#nuxt`
|
|
630
|
+
]
|
|
631
|
+
),
|
|
632
|
+
astro: scaffold(
|
|
633
|
+
"src/gateway-config.ts",
|
|
634
|
+
`
|
|
635
|
+
/* \u2500\u2500 src/middleware.ts \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
636
|
+
import { defineMiddleware } from 'astro:middleware'
|
|
637
|
+
import { createFetchMiddleware } from '@rebilder/gateway/fetch'
|
|
638
|
+
import { gatewayConfig } from './gateway-config'
|
|
639
|
+
|
|
640
|
+
const gateway = createFetchMiddleware(gatewayConfig)
|
|
641
|
+
|
|
642
|
+
export const onRequest = defineMiddleware((context, next) => gateway(context.request, () => next()))
|
|
643
|
+
`,
|
|
644
|
+
[
|
|
645
|
+
'Then add src/middleware.ts. Astro runs middleware per request only on on-demand rendered pages (an adapter plus `output: "server"` or `export const prerender = false`).',
|
|
646
|
+
`Full guide: ${DOCS}/frameworks#astro`
|
|
647
|
+
]
|
|
648
|
+
),
|
|
649
|
+
"react-router": scaffold(
|
|
650
|
+
"app/gateway-config.server.ts",
|
|
651
|
+
`
|
|
652
|
+
/* \u2500\u2500 app/root.tsx (React Router 8, or 7.9+ with future.v8_middleware) \u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
653
|
+
import type { Route } from './+types/root'
|
|
654
|
+
import { createFetchMiddleware } from '@rebilder/gateway/fetch'
|
|
655
|
+
import { gatewayConfig } from './gateway-config.server'
|
|
656
|
+
|
|
657
|
+
const gateway = createFetchMiddleware(gatewayConfig)
|
|
658
|
+
|
|
659
|
+
export const middleware: Route.MiddlewareFunction[] = [({ request }, next) => gateway(request, next)]
|
|
660
|
+
`,
|
|
661
|
+
[
|
|
662
|
+
"Then export `middleware` from app/root.tsx. On React Router 7, enable `future: { v8_middleware: true }` in react-router.config.ts first.",
|
|
663
|
+
`Full guide: ${DOCS}/frameworks#react-router`
|
|
664
|
+
]
|
|
665
|
+
),
|
|
666
|
+
remix: scaffold(
|
|
667
|
+
"app/gateway-config.server.ts",
|
|
668
|
+
`
|
|
669
|
+
/* \u2500\u2500 server.ts (Remix v2 with a custom Express server) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
670
|
+
import express from 'express'
|
|
671
|
+
import { createRequestHandler } from '@remix-run/express'
|
|
672
|
+
import { createGatewayMiddleware } from '@rebilder/gateway/node'
|
|
673
|
+
import { gatewayConfig } from './app/gateway-config.server'
|
|
674
|
+
|
|
675
|
+
const app = express()
|
|
676
|
+
app.use(createGatewayMiddleware(gatewayConfig)) // before Remix
|
|
677
|
+
app.all('*', createRequestHandler({ build: await import('./build/server/index.js') }))
|
|
678
|
+
`,
|
|
679
|
+
[
|
|
680
|
+
"Remix v2 has no middleware, so the gateway runs as Express middleware in front of `createRequestHandler`.",
|
|
681
|
+
`Full guide: ${DOCS}/frameworks#remix`
|
|
682
|
+
]
|
|
683
|
+
),
|
|
684
|
+
hono: scaffold(
|
|
685
|
+
"src/gateway-config.ts",
|
|
686
|
+
`
|
|
687
|
+
/* \u2500\u2500 src/index.ts (Hono) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
688
|
+
import { Hono } from 'hono'
|
|
689
|
+
import { createFetchMiddleware } from '@rebilder/gateway/fetch'
|
|
690
|
+
import { gatewayConfig } from './gateway-config'
|
|
691
|
+
|
|
692
|
+
const gateway = createFetchMiddleware(gatewayConfig)
|
|
693
|
+
const app = new Hono()
|
|
694
|
+
|
|
695
|
+
app.use(async (c, next) => {
|
|
696
|
+
let passed = false
|
|
697
|
+
const res = await gateway(c.req.raw, async () => {
|
|
698
|
+
passed = true
|
|
699
|
+
await next()
|
|
700
|
+
return c.res
|
|
701
|
+
})
|
|
702
|
+
if (!passed) return res // markdown, answered before any route ran
|
|
703
|
+
c.res = undefined // clear first, so Hono does not copy the old headers over ours
|
|
704
|
+
c.res = res
|
|
705
|
+
})
|
|
706
|
+
`,
|
|
707
|
+
[
|
|
708
|
+
"Register the middleware before your routes. It works the same on Workers, Bun, Deno and Node.",
|
|
709
|
+
`Full guide: ${DOCS}/frameworks#hono`
|
|
710
|
+
]
|
|
711
|
+
),
|
|
712
|
+
bun: scaffold(
|
|
713
|
+
"gateway-config.ts",
|
|
714
|
+
`
|
|
715
|
+
/* \u2500\u2500 server.ts (Bun) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
716
|
+
import { createFetchMiddleware } from '@rebilder/gateway/fetch'
|
|
717
|
+
import { gatewayConfig } from './gateway-config'
|
|
718
|
+
import { app } from './app' // TODO: your existing (request) => Response handler
|
|
719
|
+
|
|
720
|
+
const gateway = createFetchMiddleware(gatewayConfig)
|
|
721
|
+
|
|
722
|
+
Bun.serve({ fetch: (request) => gateway(request, () => app(request)) })
|
|
723
|
+
`,
|
|
724
|
+
[
|
|
725
|
+
"Wrap your existing fetch handler. Requests served by Bun.serve `routes` skip `fetch`, so wrap those handlers too.",
|
|
726
|
+
`Full guide: ${DOCS}/runtimes#bun`
|
|
727
|
+
]
|
|
728
|
+
),
|
|
729
|
+
deno: scaffold(
|
|
730
|
+
"gateway-config.ts",
|
|
731
|
+
`
|
|
732
|
+
/* \u2500\u2500 main.ts (Deno) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
733
|
+
import { createFetchMiddleware } from '@rebilder/gateway/fetch'
|
|
734
|
+
import { gatewayConfig } from './gateway-config.ts'
|
|
735
|
+
import { app } from './app.ts' // TODO: your existing (request) => Response handler
|
|
736
|
+
|
|
737
|
+
const gateway = createFetchMiddleware(gatewayConfig)
|
|
738
|
+
|
|
739
|
+
Deno.serve((request) => gateway(request, () => app(request)))
|
|
740
|
+
`,
|
|
741
|
+
["Wrap your existing handler in Deno.serve.", `Full guide: ${DOCS}/runtimes#deno`]
|
|
742
|
+
),
|
|
743
|
+
netlify: scaffold(
|
|
744
|
+
"gateway-config.ts",
|
|
745
|
+
`
|
|
746
|
+
/* \u2500\u2500 netlify/edge-functions/rebilder.ts \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
747
|
+
import type { Config, Context } from '@netlify/edge-functions'
|
|
748
|
+
import { createFetchMiddleware } from '@rebilder/gateway/fetch'
|
|
749
|
+
import { gatewayConfig } from '../../gateway-config.ts'
|
|
750
|
+
|
|
751
|
+
const gateway = createFetchMiddleware(gatewayConfig)
|
|
752
|
+
|
|
753
|
+
export default (request: Request, context: Context) => gateway(request, () => context.next())
|
|
754
|
+
|
|
755
|
+
export const config: Config = { path: '/*', excludedPath: ['/*.css', '/*.js'] }
|
|
756
|
+
`,
|
|
757
|
+
[
|
|
758
|
+
"Then add the edge function. It answers agents at the edge and passes everything else to your site with `context.next()`.",
|
|
759
|
+
`Full guide: ${DOCS}/runtimes#netlify`
|
|
760
|
+
]
|
|
761
|
+
),
|
|
762
|
+
vercel: scaffold(
|
|
763
|
+
"gateway-config.ts",
|
|
764
|
+
`
|
|
765
|
+
/* \u2500\u2500 middleware.ts (Vercel Routing Middleware, outside Next.js) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500 */
|
|
766
|
+
import { next } from '@vercel/functions'
|
|
767
|
+
import { handleRequest, negotiationHeaders } from '@rebilder/gateway/fetch'
|
|
768
|
+
import { gatewayConfig } from './gateway-config'
|
|
769
|
+
|
|
770
|
+
export default async function middleware(request: Request) {
|
|
771
|
+
const served = await handleRequest(request, gatewayConfig)
|
|
772
|
+
return served ?? next({ headers: Object.fromEntries(negotiationHeaders(gatewayConfig, new URL(request.url))) })
|
|
773
|
+
}
|
|
774
|
+
`,
|
|
775
|
+
[
|
|
776
|
+
"Then add middleware.ts at the project root. In a Next.js project, run `rebilder init --framework next` instead.",
|
|
777
|
+
`Full guide: ${DOCS}/runtimes#vercel`
|
|
778
|
+
]
|
|
779
|
+
)
|
|
527
780
|
};
|
|
528
781
|
|
|
529
782
|
// src/disclosure.ts
|
|
@@ -807,6 +1060,25 @@ function checkSuite(report, failOn, ctx) {
|
|
|
807
1060
|
return { xml, tests, failures, errors };
|
|
808
1061
|
}
|
|
809
1062
|
|
|
1063
|
+
// src/next-steps.ts
|
|
1064
|
+
function nextSteps(result) {
|
|
1065
|
+
if (result.outcome.kind !== "scored") return [];
|
|
1066
|
+
const found = new Set(result.facts.map((fact) => fact.kind));
|
|
1067
|
+
const missing = result.factProfile.core.filter((kind) => !found.has(kind));
|
|
1068
|
+
const steps = [];
|
|
1069
|
+
if (missing.length > 0) {
|
|
1070
|
+
steps.push(`Check these business details: ${missing.join(", ")}. They were not detected in this capture (heuristic); verify the page before adding or changing content.`);
|
|
1071
|
+
} else {
|
|
1072
|
+
steps.push("The expected core business details were detected (heuristic). Review their accuracy against your current products, services and policies.");
|
|
1073
|
+
}
|
|
1074
|
+
const first = result.recommendations[0];
|
|
1075
|
+
if (first !== void 0) steps.push(`Start with: ${first.title}. ${first.detail}`);
|
|
1076
|
+
steps.push(result.cost.negotiatedBytes === null ? "To connect your existing information, run rebilder init in your project. Review the generated configuration and connect your real data before deployment." : "Compare the two responses with rebilder diff <url> and confirm the same business facts reach customers and assistants.");
|
|
1077
|
+
steps.push("After updating your site, run rebilder check <url> again. Export --format markdown --out review.md to share the findings with your team.");
|
|
1078
|
+
steps.push("This scan measures page readability; it does not measure customer demand, AI recommendations or sales.");
|
|
1079
|
+
return steps;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
810
1082
|
// src/format/markdown.ts
|
|
811
1083
|
function renderMarkdown(payload, ctx) {
|
|
812
1084
|
switch (payload.command) {
|
|
@@ -843,6 +1115,10 @@ function checkSection(report) {
|
|
|
843
1115
|
"",
|
|
844
1116
|
`${result.measuredWeight} of the 100 points are measured; ${result.heuristicWeight} are heuristic.`,
|
|
845
1117
|
"",
|
|
1118
|
+
"### Your next steps",
|
|
1119
|
+
"",
|
|
1120
|
+
...nextSteps(result).map((step) => `- ${escapeCell(step)}`),
|
|
1121
|
+
"",
|
|
846
1122
|
"| Check | Points | Basis |",
|
|
847
1123
|
"| --- | ---: | --- |"
|
|
848
1124
|
);
|
|
@@ -928,20 +1204,20 @@ function diffSection(diff) {
|
|
|
928
1204
|
return out.join("\n");
|
|
929
1205
|
}
|
|
930
1206
|
function initSection(payload, ctx) {
|
|
931
|
-
const { scaffold } = payload;
|
|
1207
|
+
const { scaffold: scaffold2 } = payload;
|
|
932
1208
|
const out = [
|
|
933
|
-
`## Rebilder gateway scaffold \u2014 ${
|
|
1209
|
+
`## Rebilder gateway scaffold \u2014 ${scaffold2.framework}`,
|
|
934
1210
|
"",
|
|
935
|
-
|
|
1211
|
+
scaffold2.detection,
|
|
936
1212
|
"",
|
|
937
|
-
`Suggested path: \`${
|
|
1213
|
+
`Suggested path: \`${scaffold2.suggestedPath}\``,
|
|
938
1214
|
"",
|
|
939
|
-
"```" +
|
|
940
|
-
|
|
1215
|
+
"```" + scaffold2.language,
|
|
1216
|
+
scaffold2.contents.trimEnd(),
|
|
941
1217
|
"```",
|
|
942
1218
|
""
|
|
943
1219
|
];
|
|
944
|
-
for (const note of
|
|
1220
|
+
for (const note of scaffold2.notes) out.push(`- ${note}`);
|
|
945
1221
|
out.push("", `<!-- generated by rebilder ${ctx.cliVersion} -->`, "");
|
|
946
1222
|
return out.join("\n");
|
|
947
1223
|
}
|
|
@@ -1125,6 +1401,9 @@ function checkBlock(report, pretty) {
|
|
|
1125
1401
|
)
|
|
1126
1402
|
);
|
|
1127
1403
|
lines.push("");
|
|
1404
|
+
lines.push(paint("Your next steps", "bold"));
|
|
1405
|
+
for (const step of nextSteps(result)) lines.push(` ${glyphs.bullet} ${step}`);
|
|
1406
|
+
lines.push("");
|
|
1128
1407
|
for (const dimension of result.dimensions) {
|
|
1129
1408
|
lines.push(...dimensionLines(dimension, pretty));
|
|
1130
1409
|
}
|
|
@@ -1320,19 +1599,19 @@ function diffBlock(diff, pretty) {
|
|
|
1320
1599
|
function text(value, unicode) {
|
|
1321
1600
|
return value === void 0 || value === null ? absent(unicode) : String(value);
|
|
1322
1601
|
}
|
|
1323
|
-
function initBlock(
|
|
1602
|
+
function initBlock(scaffold2, pretty) {
|
|
1324
1603
|
const { paint } = pretty;
|
|
1325
1604
|
const lines = [
|
|
1326
|
-
paint(`Detected framework: ${
|
|
1327
|
-
paint(` ${
|
|
1605
|
+
paint(`Detected framework: ${scaffold2.framework}`, "bold"),
|
|
1606
|
+
paint(` ${scaffold2.detection}`, "gray"),
|
|
1328
1607
|
"",
|
|
1329
|
-
paint(`Suggested path: ${
|
|
1608
|
+
paint(`Suggested path: ${scaffold2.suggestedPath}`, "gray"),
|
|
1330
1609
|
"",
|
|
1331
|
-
|
|
1610
|
+
scaffold2.contents.trimEnd()
|
|
1332
1611
|
];
|
|
1333
|
-
if (
|
|
1612
|
+
if (scaffold2.notes.length > 0) {
|
|
1334
1613
|
lines.push("");
|
|
1335
|
-
for (const note of
|
|
1614
|
+
for (const note of scaffold2.notes) lines.push(paint(` ${note}`, "gray"));
|
|
1336
1615
|
}
|
|
1337
1616
|
return lines;
|
|
1338
1617
|
}
|
|
@@ -1379,7 +1658,7 @@ var EXIT_TABLE = [
|
|
|
1379
1658
|
` ${EXIT.PROBE} probe failed / target unreachable \u2014 infrastructure, not a score failure`,
|
|
1380
1659
|
` ${EXIT.POLICY} blocked by policy (SSRF guard, robots opt-out, probe budget spent)`
|
|
1381
1660
|
];
|
|
1382
|
-
var GENERAL = `rebilder \u2014
|
|
1661
|
+
var GENERAL = `rebilder \u2014 help AI assistants understand your business website.
|
|
1383
1662
|
|
|
1384
1663
|
USAGE
|
|
1385
1664
|
rebilder check <url...> [--format ${FORMATS.join("|")}] [--fail-on ${GRADES.join("|")}]
|
|
@@ -1392,6 +1671,15 @@ USAGE
|
|
|
1392
1671
|
rebilder help <command> detail for one command
|
|
1393
1672
|
rebilder --version
|
|
1394
1673
|
|
|
1674
|
+
START HERE
|
|
1675
|
+
1. Check an important product, service or location page.
|
|
1676
|
+
2. Review the business details and suggested next steps in the report.
|
|
1677
|
+
3. Run rebilder init in your project to prepare a website connection.
|
|
1678
|
+
4. Update your site and rerun the check to verify the result.
|
|
1679
|
+
|
|
1680
|
+
Share a report: rebilder check <url> --format markdown --out review.md
|
|
1681
|
+
A scan measures readability, not AI recommendations, customer demand or sales.
|
|
1682
|
+
|
|
1395
1683
|
EXIT CODES (a stable contract; never renumbered)
|
|
1396
1684
|
${EXIT_TABLE.join("\n")}
|
|
1397
1685
|
|
|
@@ -1453,7 +1741,9 @@ var INIT = `rebilder init
|
|
|
1453
1741
|
reads nothing outside the working directory.
|
|
1454
1742
|
|
|
1455
1743
|
OPTIONS
|
|
1456
|
-
--framework next
|
|
1744
|
+
--framework <name> override detection: next, node, edge, shopify,
|
|
1745
|
+
fetch, sveltekit, nuxt, astro, react-router,
|
|
1746
|
+
remix, hono, bun, deno, netlify, vercel
|
|
1457
1747
|
--out <file> write the scaffold to a file
|
|
1458
1748
|
--format ${FORMATS.join("|")} junit is refused: init makes no observations
|
|
1459
1749
|
|
|
@@ -1487,7 +1777,7 @@ function helpText(topic) {
|
|
|
1487
1777
|
}
|
|
1488
1778
|
|
|
1489
1779
|
// src/cli.ts
|
|
1490
|
-
var CLI_VERSION = "0.
|
|
1780
|
+
var CLI_VERSION = "0.3.0";
|
|
1491
1781
|
async function runCli(argv, runtime) {
|
|
1492
1782
|
const caps = detectCapabilities({
|
|
1493
1783
|
env: runtime.env,
|
|
@@ -1547,8 +1837,8 @@ async function execute(command, runtime) {
|
|
|
1547
1837
|
return { payload: { command: "diff", diff }, exitCode: exitCodeFor(diff.report, null) };
|
|
1548
1838
|
}
|
|
1549
1839
|
case "init": {
|
|
1550
|
-
const
|
|
1551
|
-
return { payload: { command: "init", scaffold }, exitCode: EXIT.OK };
|
|
1840
|
+
const scaffold2 = await runInit(command, runtime);
|
|
1841
|
+
return { payload: { command: "init", scaffold: scaffold2 }, exitCode: EXIT.OK };
|
|
1552
1842
|
}
|
|
1553
1843
|
case "badge": {
|
|
1554
1844
|
return { payload: { command: "badge", badge: runBadge(command) }, exitCode: EXIT.OK };
|