@voyant-travel/worker-runtime 0.1.0 → 0.2.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 CHANGED
@@ -15,7 +15,9 @@ fixes to this load-bearing code path arrive via a dependency bump.
15
15
  stripping the prefix and preserving method/headers/body/search. When
16
16
  `loadAuthApp` is set, `/api/auth/*` dispatches to the lean auth app without
17
17
  instantiating the full API graph (the cold-start outage fix), and non-OPTIONS
18
- auth traffic warms the full app in the background via `ctx.waitUntil`.
18
+ auth traffic warms the full app in the background via `ctx.waitUntil`. Hosts
19
+ can pass `rewriteAppPath` for compatibility redirects that must happen after
20
+ prefix stripping and before the request reaches the app.
19
21
  - **`createWorkerFetch({ api, ssr })`** — the Worker `fetch` entrypoint:
20
22
  API-prefixed requests go to the dispatch, everything else to the SSR handler.
21
23
  - **`withActiveRouteSsrManifest(streamHandler)`** — restricts the TanStack
@@ -43,8 +45,8 @@ const fetch = createWorkerFetch<CloudflareBindings>({
43
45
  export default { fetch }
44
46
  ```
45
47
 
46
- Scheduled (cron) handlers, Durable Objects, and workflow wiring remain
47
- app-owned composition — see RFC §4.4.
48
+ Scheduled (cron) handlers and workflow wiring remain app-owned composition —
49
+ see RFC §4.4.
48
50
 
49
51
  ## License
50
52
 
@@ -17,6 +17,11 @@ export interface CreateApiDispatchOptions<Env, Ctx extends WaitUntilContext = Wa
17
17
  loadAuthApp?: AppLoader<Env, Ctx>;
18
18
  /** Hosting prefix stripped before dispatch. Default `/api`. */
19
19
  apiPrefix?: string;
20
+ /**
21
+ * Optional post-strip app-path rewrite. Runs after `/api` is removed and
22
+ * before the request is forwarded to the app.
23
+ */
24
+ rewriteAppPath?: (pathname: string) => string;
20
25
  /** Auth sub-prefix served by the lean app. Default `${apiPrefix}/auth`. */
21
26
  authPrefix?: string;
22
27
  /** Background-warm the full app on auth traffic. Default true. */
@@ -1 +1 @@
1
- {"version":3,"file":"api-dispatch.d.ts","sourceRoot":"","s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CAAA;IACvC,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAA;IACxC,gFAAgF;IAChF,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAA;IACvC,QAAQ,CAAC,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAA;CAClE;AAMD;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,GAAG,SAAS,gBAAgB,GAAG,gBAAgB,EACpF,OAAO,EAAE,wBAAwB,CAAC,GAAG,EAAE,GAAG,CAAC,GAC1C,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,CAiDvB"}
@@ -29,7 +29,8 @@ export function createApiDispatch(options) {
29
29
  function toAppRequest(request) {
30
30
  const url = new URL(request.url);
31
31
  const stripped = url.pathname.slice(apiPrefix.length) || "/";
32
- const appUrl = new URL(stripped, url.origin);
32
+ const appPath = options.rewriteAppPath?.(stripped) ?? stripped;
33
+ const appUrl = new URL(appPath, url.origin);
33
34
  appUrl.search = url.search;
34
35
  const bodyless = request.method === "GET" || request.method === "HEAD";
35
36
  return new Request(appUrl.toString(), {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voyant-travel/worker-runtime",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -48,10 +48,10 @@
48
48
  "directory": "packages/worker-runtime"
49
49
  },
50
50
  "scripts": {
51
- "typecheck": "tsc --noEmit",
51
+ "typecheck": "tsc -p tsconfig.typecheck.json",
52
52
  "lint": "biome check src/ tests/",
53
53
  "test": "vitest run",
54
- "build": "tsc -p tsconfig.json",
54
+ "build": "tsc -p tsconfig.build.json",
55
55
  "clean": "rm -rf dist tsconfig.tsbuildinfo"
56
56
  },
57
57
  "main": "./dist/index.js",