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