Skip to content

Add @fedify/nuxt package for Nuxt integration#674

Open
2chanhaeng wants to merge 11 commits intofedify-dev:mainfrom
2chanhaeng:fedify/nuxt
Open

Add @fedify/nuxt package for Nuxt integration#674
2chanhaeng wants to merge 11 commits intofedify-dev:mainfrom
2chanhaeng:fedify/nuxt

Conversation

@2chanhaeng
Copy link
Copy Markdown
Contributor

Add @fedify/nuxt package for Nuxt integration

Closes #149

Changes

New package: @fedify/nuxt

  • src/mod.ts: Defines the Nuxt module (defineNuxtModule) that:

    • Resolves user-configured federationModule and optional
      contextDataFactoryModule paths
    • Generates a virtual template that wires the Federation instance
      into a Nitro server handler
    • Registers a server plugin for deferred 406 handling
  • src/runtime/server/middleware.ts: Creates the Fedify middleware
    (defineEventHandler) that intercepts incoming requests, converts
    them via toWebRequest, and delegates to federation.fetch().
    Non-federation requests fall through to Nuxt routing.

  • src/runtime/server/logic.ts: Pure-logic helpers
    (fetchWithFedify, resolveDeferredNotAcceptable) that determine
    whether Fedify handled the request, the framework should take over
    (404 fallthrough), or a deferred 406 should be returned.

  • src/runtime/server/plugin.ts: Nitro beforeResponse hook
    plugin that resolves deferred 406 Not Acceptable responses when
    Fedify owns the route but the client does not accept ActivityPub and
    Nuxt itself returns 404.

  • src/mod.test.ts: Unit tests covering:

    1. Fedify handles a federation request successfully (returns JSON-LD)
    2. Non-federation requests are delegated to the framework
      (onNotFound fallthrough)
    3. 406 response when client does not accept ActivityPub and no
      framework route matches
    4. Framework response is preserved for shared HTML routes

Documentation

  • docs/manual/integration.md: Added Nuxt section with
    installation instructions, module configuration, and context data
    factory usage example.

Configuration updates

  • Added @fedify/nuxt to workspace configs (deno.json, deno.lock,
    pnpm-workspace.yaml, pnpm-lock.yaml)
  • Added @fedify/nuxt to AGENTS.md, CONTRIBUTING.md, and
    packages/fedify/README.md package listings
  • Added Nuxt-related terms to cspell.json and .hongdown.toml
  • Added tunnel task to mise.toml
  • Recorded the addition in CHANGES.md

Agent skill improvements (non-functional)

  • Updated create-integration-package, add-to-fedify-init, and
    create-example-app-with-integration skill docs with clarified
    guidance on version verification, fallthrough/406 behavior, template
    file references, and host restriction configuration.

Co-Authored-By: GPT-5.3-codex

@issues-auto-labeler issues-auto-labeler bot added component/build Build system and packaging component/federation Federation object related component/integration Web framework integration labels Apr 13, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 13, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a new @fedify/nuxt Nuxt 4 / Nitro integration: module wiring, runtime middleware and plugin for deferred 406 handling, request/response helpers and tests; packages, build config, docs, workspace/tooling updates, and minor agent-skill docs edits.

Changes

Cohort / File(s) Summary
Nuxt integration core
packages/nuxt/src/mod.ts, packages/nuxt/src/runtime/server/lib.ts, packages/nuxt/src/runtime/server/logic.ts, packages/nuxt/src/runtime/server/middleware.ts, packages/nuxt/src/runtime/server/plugin.ts
New Nuxt module and runtime: exported types/options, template-based middleware registration, deferred-406 constants, fetch normalization (fetchWithFedify), middleware factory (createFedifyMiddleware) and plugin to resolve/apply deferred 406 responses.
Package manifests & build
packages/nuxt/package.json, packages/nuxt/deno.json, packages/nuxt/tsdown.config.ts
New npm/Deno manifests and tsdown config: exports map, peer/dev deps, scripts, deno metadata, and tsdown ESM/CJS outputs with dual-type declarations.
Runtime tests
packages/nuxt/src/mod.test.ts
New fixture-based tests covering fetchWithFedify and resolveDeferredNotAcceptable flows (handled, not-found, not-acceptable, deferred suppression).
Docs & changelog
packages/nuxt/README.md, docs/manual/integration.md, CHANGES.md, packages/fedify/README.md
New package README, integration docs, changelog entry, and package table/readme updates describing the Nuxt integration.
Workspace & tooling
deno.json, pnpm-workspace.yaml, mise.toml, cspell.json, .hongdown.toml
Added packages/nuxt to Deno/pnpm workspaces, added Mise tunnel task, added nuxt/nuxi to cspell, and added @fedify/nuxt to proper-nouns.
Agent skills & example docs
.agents/skills/.../SKILL.md, .agents/skills/create-example-app-with-integration/example/README.md
Doc edits: replace placeholder refs with relative links, explicit template checklist, example README wording/links, and expanded skill/setup/testing instructions.
Monorepo lists
AGENTS.md, CONTRIBUTING.md, packages/fedify/README.md
Added packages/nuxt/* / @fedify/nuxt entries to monorepo package lists and README tables.

Sequence Diagram

sequenceDiagram
    participant Client
    participant Nitro as Nitro/H3_Event_Handler
    participant FedifyMiddleware as Fedify_Middleware
    participant FedifyFetch as fetchWithFedify
    participant Federation as Federation_Instance
    participant Framework as Nuxt_Handler
    participant Plugin as Deferred_Response_Plugin

    Client->>Nitro: HTTP Request
    Nitro->>FedifyMiddleware: Invoke handler (H3 event)
    FedifyMiddleware->>FedifyMiddleware: toWebRequest / compute contextData
    FedifyMiddleware->>FedifyFetch: fetchWithFedify(fetch, request, contextData)
    FedifyFetch->>Federation: federation.fetch(request, { onNotFound, onNotAcceptable, ... })
    alt federation handled (ActivityPub)
        Federation-->>FedifyFetch: ActivityPub Response (e.g., 200, application/activity+json)
        FedifyFetch-->>FedifyMiddleware: { kind: "handled", response }
        FedifyMiddleware->>Nitro: return federation response
        Nitro-->>Client: federation response
    else not-found
        Federation-->>FedifyFetch: NotFound sentinel (internal)
        FedifyFetch-->>FedifyMiddleware: { kind: "not-found" }
        FedifyMiddleware->>Nitro: return undefined (delegate)
        Nitro->>Framework: continue to Nuxt handler
        Framework-->>Nitro: framework response
        Nitro-->>Client: framework response
    else not-acceptable
        Federation-->>FedifyFetch: NotAcceptable sentinel (internal)
        FedifyFetch-->>FedifyMiddleware: { kind: "not-acceptable" }
        FedifyMiddleware->>FedifyMiddleware: set deferred flag in event.context
        FedifyMiddleware->>Nitro: return undefined (delegate)
        Nitro->>Framework: continue to Nuxt handler
        Framework-->>Nitro: framework response
        Nitro->>Plugin: beforeResponse hook
        Plugin->>Plugin: resolveDeferredNotAcceptable(deferred, frameworkStatus)
        alt returns 406
            Plugin->>Nitro: set status, headers, body -> 406 Not Acceptable
        else undefined
            Plugin->>Nitro: leave framework response intact
        end
        Nitro-->>Client: final response
    end
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • dahlia
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding a new @fedify/nuxt package for Nuxt integration, which aligns with the primary objective and changeset.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing the new package structure, documentation, configuration updates, and skill improvements introduced in this PR.
Linked Issues check ✅ Passed The PR successfully addresses issue #149 by delivering an official Nuxt integration for Fedify with complete implementation of the @fedify/nuxt package, documentation, tests, and configuration updates.
Out of Scope Changes check ✅ Passed All changes are within scope: the new @fedify/nuxt package and its supporting documentation/configuration updates directly fulfill the integration objective, and agent skill documentation updates provide necessary guidance.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the @fedify/nuxt package to integrate Fedify with the Nuxt framework, providing a module, Nitro middleware, and a plugin for deferred 406 Not Acceptable handling. It also updates documentation, agent skills, and workspace configurations. Feedback recommends improving TypeScript type safety by using specific types from @nuxt/kit and h3, and suggests extracting the "Not acceptable" response body into a shared constant to prevent duplication across the runtime logic and plugin.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.agents/skills/create-example-app-with-integration/SKILL.md (1)

180-193: ⚠️ Potential issue | 🟠 Major

Close the bash fence immediately after the curl example.

Line 180 opens a fence, but it is only closed at Line 193. That makes the “Lint, format, and final checks” section render as code.

Suggested fix
 ~~~~ bash
 curl -H "Accept: application/activity+json" http://localhost:0000/users/demo
+~~~~
 
 Lint, format, and final checks
 ------------------------------
@@
-~~~~
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.agents/skills/create-example-app-with-integration/SKILL.md around lines 180
- 193, The markdown code fence opened with "~~~~ bash" around the curl example
is left open; close that fence immediately after the curl command so the
following "Lint, format, and final checks" section is not rendered as code—i.e.,
move or add the matching closing fence "~~~~" directly after the line with `curl
-H "Accept: application/activity+json" http://localhost:0000/users/demo` (refer
to the fenced block starting with "~~~~ bash" in SKILL.md) and ensure subsequent
text is plain markdown outside the fence.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.agents/skills/create-example-app-with-integration/SKILL.md:
- Line 178: Update the wording in SKILL.md where the sentence reads "If the
`test:examples` can not be run, just run the server and test with curl:" to use
the standard single-word form "cannot" (i.e., change "can not" to "cannot") so
the line becomes "If the `test:examples` cannot be run, just run the server and
test with curl:".

In `@docs/manual/integration.md`:
- Around line 397-418: The Nuxt docs use inconsistent path styling; update the
Nuxt section so all file and module paths are wrapped in asterisks instead of
underscores or backticks—replace occurrences like _server/federation.ts_,
_nuxt.config.ts_, and `~/server/federation` with *server/federation.ts*,
*nuxt.config.ts*, and *~/server/federation* respectively (in the block that
shows createFederation / MemoryKvStore and the module enablement) so path
styling matches the repo guideline.

In `@packages/nuxt/README.md`:
- Around line 71-72: Replace the inline code backticks around the default module
path with asterisks: change the instance that reads "`@fedify/nuxt` loads your
Federation instance from `~/server/federation`" so that the module and path use
asterisk wrapping (e.g., *@fedify/nuxt* and *~/server/federation*) to comply
with the repo Markdown rule; update the README line containing "@fedify/nuxt"
and "~/server/federation" accordingly.

In `@packages/nuxt/src/mod.test.ts`:
- Line 2: Replace the runtime-specific import of the test entrypoint by
importing the test function from the runtime-agnostic package: change the import
of test from "node:test" to "@fedify/fixture" (i.e., replace the existing import
statement that references node:test with one that imports test from
`@fedify/fixture`), ensuring any usages of the test identifier remain unchanged.

In `@packages/nuxt/src/runtime/server/logic.ts`:
- Around line 47-53: Add a JSDoc block above the exported function
resolveDeferredNotAcceptable that documents its purpose (handle deferred
requests that should return a 406 Not Acceptable when the framework routed to
404), describes parameters isDeferred:boolean and frameworkStatus:number,
explains the return type Response|undefined and the conditions when
createNotAcceptableResponse() is returned, and notes that this is part of the
deferred 406 handling pattern for public API consumers; keep the comment concise
and follow existing project JSDoc style.
- Around line 22-45: Add a JSDoc block to the exported function fetchWithFedify
describing its purpose, parameters (fetcher: (request: Request, options:
FederationFetchOptions<unknown>) => Promise<Response>, request: Request,
contextData: unknown) and return value (Promise<FetchResult>), and note the
behavior/assumption that a response equal to DUMMY_NOT_FOUND_RESPONSE maps to {
kind: "not-found" } and any Response with status 406 is treated as { kind:
"not-acceptable" } (which relies on user handlers not returning 406 for
unrelated reasons); reference DUMMY_NOT_FOUND_RESPONSE and
createNotAcceptableResponse in the doc so callers understand the special-case
mappings.

In `@packages/nuxt/src/runtime/server/middleware.ts`:
- Around line 20-23: Add a JSDoc block above the exported createFedifyMiddleware
function that documents its parameters and return value: describe the
"federation" parameter type/expected shape (unknown but clarify expected usage),
the optional "contextDataFactory" callback signature ((event: unknown, request:
Request) => unknown) and when it is invoked, the middleware behavior (what the
returned function does, side effects, and that it returns a
Connect/Node/Fetch-style middleware handler), and the return type expectations
(e.g., middleware function or handler). Use the function name
createFedifyMiddleware and mention the contextDataFactory callback to make the
doc discoverable.

---

Outside diff comments:
In @.agents/skills/create-example-app-with-integration/SKILL.md:
- Around line 180-193: The markdown code fence opened with "~~~~ bash" around
the curl example is left open; close that fence immediately after the curl
command so the following "Lint, format, and final checks" section is not
rendered as code—i.e., move or add the matching closing fence "~~~~" directly
after the line with `curl -H "Accept: application/activity+json"
http://localhost:0000/users/demo` (refer to the fenced block starting with "~~~~
bash" in SKILL.md) and ensure subsequent text is plain markdown outside the
fence.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 833b06e0-e342-4d98-af3c-fa0f0c532116

📥 Commits

Reviewing files that changed from the base of the PR and between 5323388 and 90757cb.

⛔ Files ignored due to path filters (2)
  • deno.lock is excluded by !**/*.lock
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (24)
  • .agents/skills/add-to-fedify-init/SKILL.md
  • .agents/skills/create-example-app-with-integration/SKILL.md
  • .agents/skills/create-example-app-with-integration/example/README.md
  • .agents/skills/create-example-app-with-integration/example/src/logging.ts
  • .agents/skills/create-integration-package/SKILL.md
  • .hongdown.toml
  • AGENTS.md
  • CHANGES.md
  • CONTRIBUTING.md
  • cspell.json
  • deno.json
  • docs/manual/integration.md
  • mise.toml
  • packages/fedify/README.md
  • packages/nuxt/README.md
  • packages/nuxt/deno.json
  • packages/nuxt/package.json
  • packages/nuxt/src/mod.test.ts
  • packages/nuxt/src/mod.ts
  • packages/nuxt/src/runtime/server/logic.ts
  • packages/nuxt/src/runtime/server/middleware.ts
  • packages/nuxt/src/runtime/server/plugin.ts
  • packages/nuxt/tsdown.config.ts
  • pnpm-workspace.yaml

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

Files with missing lines Coverage Δ
packages/nuxt/src/runtime/server/lib.ts 100.00% <100.00%> (ø)
packages/nuxt/src/runtime/server/logic.ts 100.00% <100.00%> (ø)

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.agents/skills/add-to-fedify-init/SKILL.md:
- Around line 37-39: Replace the inline link and plain file paths in the
sentence that mentions WebFrameworkDescription, changing `./init/framework.ts`
and `packages/init/src/types.ts` to wrapped paths (*./init/framework.ts*,
*packages/init/src/types.ts*) and convert the inline link to a reference-style
link (e.g., [init/framework.ts][init-framework]) with the corresponding
reference entry placed at the end of the section; update the sentence to refer
to the reference label and ensure the symbol WebFrameworkDescription remains
mentioned so you can find the exact line to edit.

In `@packages/nuxt/deno.json`:
- Line 24: The "check" npm script currently only runs deno check on "src/*.ts"
which skips nested runtime files (e.g., src/runtime/server/); update the "check"
script (the "check" key value that currently contains "deno fmt --check && deno
lint && deno check src/*.ts") to use a recursive glob such as "src/**/*.ts" or
explicitly include the runtime folder (for example add
"src/runtime/server/**/*.ts") so that deno check covers all nested runtime
TypeScript files.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 44c494fa-0e71-490b-ad31-ac3a6bde1a5c

📥 Commits

Reviewing files that changed from the base of the PR and between 90757cb and 7c3f831.

⛔ Files ignored due to path filters (2)
  • deno.lock is excluded by !**/*.lock
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (25)
  • .agents/skills/add-to-fedify-init/SKILL.md
  • .agents/skills/create-example-app-with-integration/SKILL.md
  • .agents/skills/create-example-app-with-integration/example/README.md
  • .agents/skills/create-example-app-with-integration/example/src/logging.ts
  • .agents/skills/create-integration-package/SKILL.md
  • .hongdown.toml
  • AGENTS.md
  • CHANGES.md
  • CONTRIBUTING.md
  • cspell.json
  • deno.json
  • docs/manual/integration.md
  • mise.toml
  • packages/fedify/README.md
  • packages/nuxt/README.md
  • packages/nuxt/deno.json
  • packages/nuxt/package.json
  • packages/nuxt/src/mod.test.ts
  • packages/nuxt/src/mod.ts
  • packages/nuxt/src/runtime/server/lib.ts
  • packages/nuxt/src/runtime/server/logic.ts
  • packages/nuxt/src/runtime/server/middleware.ts
  • packages/nuxt/src/runtime/server/plugin.ts
  • packages/nuxt/tsdown.config.ts
  • pnpm-workspace.yaml

- Use @fedify/fixture instead of node:test in mod.test.ts
- Type event parameter as H3Event instead of unknown in middleware.ts

Co-Authored-By: Claude (claude-opus-4-20250514)
Move NOT_ACCEPTABLE_BODY and DEFERRED_NOT_ACCEPTABLE_CONTEXT_KEY into
a shared lib.ts to avoid string duplication across logic.ts and
plugin.ts.

Co-Authored-By: Claude (claude-opus-4-20250514)
- Close unclosed bash code fence in SKILL.md
- Fix "can not" to "cannot" in SKILL.md
- Use asterisk-wrapped file paths in README.md and integration.md

Co-Authored-By: Claude (claude-opus-4-20250514)
Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/nuxt/src/mod.ts`:
- Around line 87-93: The current contextFactoryResolver silently treats a
non-function export from contextDataFactoryModule as undefined, causing hidden
misconfiguration; update the resolver logic around contextFactoryResolver to
check whether contextDataFactoryModule.default ??
contextDataFactoryModule.contextDataFactory is present and is a function, and if
it exists but is not a function throw a descriptive Error (mentioning
contextDataFactoryModule and the expected function export) instead of assigning
undefined, otherwise assign the function to contextDataFactory as before.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: d6eaeee1-e713-4a85-9ec6-0ff5fd614e21

📥 Commits

Reviewing files that changed from the base of the PR and between a5b7b8d and a2d0460.

📒 Files selected for processing (2)
  • packages/nuxt/deno.json
  • packages/nuxt/src/mod.ts

Comment on lines +87 to +93
const contextFactoryResolver = contextDataFactoryModule == null
? "const contextDataFactory = undefined;"
: [
"const contextDataFactory =",
" contextFactoryModule.default ??",
" contextFactoryModule.contextDataFactory;",
].join("\n");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fail fast when contextDataFactoryModule does not export a function.

At Lines 90-93, a non-function export is treated as undefined, so misconfiguration is silently ignored and request context data disappears unexpectedly. Add a runtime type check and throw a descriptive error.

🔧 Proposed fix
           const contextFactoryResolver = contextDataFactoryModule == null
             ? "const contextDataFactory = undefined;"
             : [
               "const contextDataFactory =",
               "  contextFactoryModule.default ??",
               "  contextFactoryModule.contextDataFactory;",
+              "if (contextDataFactory != null && typeof contextDataFactory !== 'function') {",
+              "  throw new TypeError(",
+              "    '@fedify/nuxt: contextDataFactoryModule must export a function as default export or named export \"contextDataFactory\".',",
+              "  );",
+              "}",
             ].join("\n");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const contextFactoryResolver = contextDataFactoryModule == null
? "const contextDataFactory = undefined;"
: [
"const contextDataFactory =",
" contextFactoryModule.default ??",
" contextFactoryModule.contextDataFactory;",
].join("\n");
const contextFactoryResolver = contextDataFactoryModule == null
? "const contextDataFactory = undefined;"
: [
"const contextDataFactory =",
" contextFactoryModule.default ??",
" contextFactoryModule.contextDataFactory;",
"if (contextDataFactory != null && typeof contextDataFactory !== 'function') {",
" throw new TypeError(",
" '@fedify/nuxt: contextDataFactoryModule must export a function as default export or named export \"contextDataFactory\".',",
" );",
"}",
].join("\n");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nuxt/src/mod.ts` around lines 87 - 93, The current
contextFactoryResolver silently treats a non-function export from
contextDataFactoryModule as undefined, causing hidden misconfiguration; update
the resolver logic around contextFactoryResolver to check whether
contextDataFactoryModule.default ?? contextDataFactoryModule.contextDataFactory
is present and is a function, and if it exists but is not a function throw a
descriptive Error (mentioning contextDataFactoryModule and the expected function
export) instead of assigning undefined, otherwise assign the function to
contextDataFactory as before.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
packages/nuxt/src/mod.ts (1)

87-93: ⚠️ Potential issue | 🟠 Major

Validate contextDataFactoryModule export type instead of silently ignoring bad config.

At Line 90–93, a non-function export is accepted and later treated as undefined, which hides configuration errors and drops context data unexpectedly.

🔧 Proposed fix
           const contextFactoryResolver = contextDataFactoryModule == null
             ? "const contextDataFactory = undefined;"
             : [
               "const contextDataFactory =",
               "  contextFactoryModule.default ??",
               "  contextFactoryModule.contextDataFactory;",
+              "if (contextDataFactory != null && typeof contextDataFactory !== 'function') {",
+              "  throw new TypeError(",
+              "    '@fedify/nuxt: contextDataFactoryModule must export a function as default export or named export \"contextDataFactory\".',",
+              "  );",
+              "}",
             ].join("\n");
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nuxt/src/mod.ts` around lines 87 - 93, The current resolver silently
treats a non-function export from contextDataFactoryModule as undefined; update
the contextFactoryResolver logic to validate that the resolved export
(contextDataFactoryModule.default ??
contextDataFactoryModule.contextDataFactory) is a function and throw a clear
error (or call Nuxt's logger/error) if it's not; specifically, in the code that
builds contextFactoryResolver, replace the unconditional assignment to
contextDataFactory with a runtime type-check that verifies typeof
contextDataFactory === "function" and fails fast referencing
contextDataFactoryModule/contextDataFactory to surface misconfiguration instead
of silently dropping context data.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.agents/skills/create-integration-package/SKILL.md:
- Line 250: Update the final validation command text that currently reads "mise
run fmt && mise run check" to the repository-standard "mise run fmt && mise
check"; locate the string in SKILL.md (the sentence starting "After
implementation, run") and replace the second invocation "mise run check" without
changing surrounding wording or formatting so the documented convention matches
the CI-style check.

In `@packages/nuxt/src/runtime/server/plugin.ts`:
- Around line 32-43: The current deferred 406 rewrite uses only the final status
(via resolveDeferredNotAcceptable/getResponseStatus) and thus converts
legitimate downstream 404 responses into 406; change the logic to only apply the
negotiated 406 when there is an actual route-miss signal rather than any 404.
Concretely, update the call/site using resolveDeferredNotAcceptable/deferred
(and related code paths) so you first check a route-miss indicator (e.g., a
boolean on deferred such as deferred.routeMiss or an explicit framework "not
found" flag on the event/context) and only proceed to setResponseStatus,
setResponseHeader and payload.body = NOT_ACCEPTABLE_BODY when negotiatedResponse
is non-null AND that route-miss flag is true; leave responses alone when a
downstream handler legitimately returned 404 but the route was matched.

---

Duplicate comments:
In `@packages/nuxt/src/mod.ts`:
- Around line 87-93: The current resolver silently treats a non-function export
from contextDataFactoryModule as undefined; update the contextFactoryResolver
logic to validate that the resolved export (contextDataFactoryModule.default ??
contextDataFactoryModule.contextDataFactory) is a function and throw a clear
error (or call Nuxt's logger/error) if it's not; specifically, in the code that
builds contextFactoryResolver, replace the unconditional assignment to
contextDataFactory with a runtime type-check that verifies typeof
contextDataFactory === "function" and fails fast referencing
contextDataFactoryModule/contextDataFactory to surface misconfiguration instead
of silently dropping context data.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c7d0ca7b-05f4-4d60-9211-cd5a98f3de04

📥 Commits

Reviewing files that changed from the base of the PR and between a2d0460 and 58807b9.

⛔ Files ignored due to path filters (2)
  • deno.lock is excluded by !**/*.lock
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (25)
  • .agents/skills/add-to-fedify-init/SKILL.md
  • .agents/skills/create-example-app-with-integration/SKILL.md
  • .agents/skills/create-example-app-with-integration/example/README.md
  • .agents/skills/create-example-app-with-integration/example/src/logging.ts
  • .agents/skills/create-integration-package/SKILL.md
  • .hongdown.toml
  • AGENTS.md
  • CHANGES.md
  • CONTRIBUTING.md
  • cspell.json
  • deno.json
  • docs/manual/integration.md
  • mise.toml
  • packages/fedify/README.md
  • packages/nuxt/README.md
  • packages/nuxt/deno.json
  • packages/nuxt/package.json
  • packages/nuxt/src/mod.test.ts
  • packages/nuxt/src/mod.ts
  • packages/nuxt/src/runtime/server/lib.ts
  • packages/nuxt/src/runtime/server/logic.ts
  • packages/nuxt/src/runtime/server/middleware.ts
  • packages/nuxt/src/runtime/server/plugin.ts
  • packages/nuxt/tsdown.config.ts
  • pnpm-workspace.yaml

the `.hongdown.toml`.

After implementation, run `mise run fmt && mise check`.
After implementation, run `mise run fmt && mise run check`.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Use the standard final validation command format.

Line 250 should use mise run fmt && mise check to match the repository’s documented convention.

✏️ Proposed fix
-After implementation, run `mise run fmt && mise run check`.
+After implementation, run `mise run fmt && mise check`.

Based on learnings, “for the standard final validation/CI-style checks, use mise run fmt && mise check.”

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
After implementation, run `mise run fmt && mise run check`.
After implementation, run `mise run fmt && mise check`.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.agents/skills/create-integration-package/SKILL.md at line 250, Update the
final validation command text that currently reads "mise run fmt && mise run
check" to the repository-standard "mise run fmt && mise check"; locate the
string in SKILL.md (the sentence starting "After implementation, run") and
replace the second invocation "mise run check" without changing surrounding
wording or formatting so the documented convention matches the CI-style check.

Comment on lines +32 to +43
const negotiatedResponse = resolveDeferredNotAcceptable(
deferred,
getResponseStatus(event),
);
if (negotiatedResponse == null) return;

setResponseStatus(event, negotiatedResponse.status);
negotiatedResponse.headers.forEach((value: string, key: string) => {
setResponseHeader(event, key, value);
});

payload.body = NOT_ACCEPTABLE_BODY;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Don't treat every downstream 404 as “Nuxt had no matching page”.

resolveDeferredNotAcceptable() only looks at the final status code, so any shared HTML route that intentionally returns 404 will be rewritten to 406 whenever Fedify matched the path but the client did not accept ActivityPub. That breaks legitimate framework responses for cases like “known route, missing user/content”.

Please gate the deferred 406 on an actual route miss signal, not on frameworkStatus === 404 alone.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/nuxt/src/runtime/server/plugin.ts` around lines 32 - 43, The current
deferred 406 rewrite uses only the final status (via
resolveDeferredNotAcceptable/getResponseStatus) and thus converts legitimate
downstream 404 responses into 406; change the logic to only apply the negotiated
406 when there is an actual route-miss signal rather than any 404. Concretely,
update the call/site using resolveDeferredNotAcceptable/deferred (and related
code paths) so you first check a route-miss indicator (e.g., a boolean on
deferred such as deferred.routeMiss or an explicit framework "not found" flag on
the event/context) and only proceed to setResponseStatus, setResponseHeader and
payload.body = NOT_ACCEPTABLE_BODY when negotiatedResponse is non-null AND that
route-miss flag is true; leave responses alone when a downstream handler
legitimately returned 404 but the route was matched.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/build Build system and packaging component/federation Federation object related component/integration Web framework integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nuxt integration

1 participant