-
Notifications
You must be signed in to change notification settings - Fork 64
Add Router Forms MVP #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
brijr
wants to merge
5
commits into
main
Choose a base branch
from
brijr/router-forms-mvp
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
207f04f
feat: add Router Forms MVP
brijr 34827c1
fix: harden Router Forms lifecycle
brijr cec0d0a
fix: track Next.js type declarations
brijr eac46f1
fix: close Router Forms review gaps
brijr 93c4796
fix: address Router Forms review findings
brijr File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: [main] | ||
|
|
||
| jobs: | ||
| application: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 9.15.9 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: pnpm | ||
| - run: pnpm install --frozen-lockfile | ||
| - run: pnpm lint | ||
| - run: pnpm typecheck | ||
| - run: pnpm test:unit | ||
| - name: Credential-free production build | ||
| run: pnpm build | ||
| env: | ||
| AUTH_SECRET: credential-free-build-secret-for-ci-only | ||
| FORM_SUBMISSION_SECRET: credential-free-form-secret-for-ci-only | ||
| FORM_RATE_LIMIT_SECRET: credential-free-rate-secret-for-ci-only | ||
|
|
||
| postgres: | ||
| runs-on: ubuntu-latest | ||
| services: | ||
| postgres: | ||
| image: postgres:16 | ||
| env: | ||
| POSTGRES_USER: postgres | ||
| POSTGRES_PASSWORD: postgres | ||
| POSTGRES_DB: router_test | ||
| ports: | ||
| - 5432:5432 | ||
| options: >- | ||
| --health-cmd "pg_isready -U postgres" | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 9.15.9 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: pnpm | ||
| - run: pnpm install --frozen-lockfile | ||
| - name: Apply forward migrations | ||
| env: | ||
| PGURL: postgresql://postgres:postgres@localhost:5432/router_test | ||
| run: | | ||
| chmod +x scripts/test-forward-migrations.sh | ||
| scripts/test-forward-migrations.sh | ||
| - run: pnpm test:db | ||
| env: | ||
| TEST_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/router_test | ||
|
|
||
| browser: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 9.15.9 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: pnpm | ||
| - run: pnpm install --frozen-lockfile | ||
| - run: pnpm exec playwright install --with-deps chromium | ||
| - run: pnpm test:browser | ||
|
|
||
| wordpress: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| - uses: shivammathur/setup-php@v2 | ||
| with: | ||
| php-version: "7.4" | ||
| - run: chmod +x integrations/wordpress/check.sh integrations/wordpress/package.sh | ||
| - run: integrations/wordpress/check.sh | ||
|
|
||
| wordpress-runtime: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 25 | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| config: [".wp-env.6.6.json", ".wp-env.latest.json"] | ||
| theme: ["twentytwentyfour", "twentytwentyone"] | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 9.15.9 | ||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 20 | ||
| cache: pnpm | ||
| - run: pnpm install --frozen-lockfile | ||
| - run: pnpm exec playwright install --with-deps chromium | ||
| - run: pnpm exec wp-env start --config="${{ matrix.config }}" --update | ||
| - run: chmod +x integrations/wordpress/test-matrix.sh | ||
| - run: integrations/wordpress/test-matrix.sh "${{ matrix.config }}" "${{ matrix.theme }}" | ||
| - if: always() | ||
| run: pnpm exec wp-env stop --config="${{ matrix.config }}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "$schema": "https://schemas.wp.org/trunk/wp-env.json", | ||
| "core": "WordPress/WordPress#6.6", | ||
| "phpVersion": "7.4", | ||
| "plugins": [ | ||
| "./integrations/wordpress/router-forms", | ||
| "./integrations/wordpress/test-fixtures/router-forms-test-api" | ||
| ], | ||
| "testsEnvironment": false, | ||
| "port": 8888 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "$schema": "https://schemas.wp.org/trunk/wp-env.json", | ||
| "core": null, | ||
| "phpVersion": "7.4", | ||
| "plugins": [ | ||
| "./integrations/wordpress/router-forms", | ||
| "./integrations/wordpress/test-fixtures/router-forms-test-api" | ||
| ], | ||
| "testsEnvironment": false, | ||
| "port": 8888 | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { readFileSync } from "node:fs"; | ||
| import { describe, expect, it } from "vitest"; | ||
|
|
||
| describe("scheduled maintenance", () => { | ||
| it("runs form rate-bucket pruning at least hourly", () => { | ||
| const config = JSON.parse(readFileSync("vercel.json", "utf8")) as { | ||
| crons: Array<{ path: string; schedule: string }>; | ||
| }; | ||
|
|
||
| expect(config.crons).toContainEqual({ | ||
| path: "/api/cron/forms-maintenance", | ||
| schedule: "17 * * * *", | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,180 @@ | ||
| import { afterEach, beforeEach, describe, expect, it } from "vitest"; | ||
| import { readFileSync } from "node:fs"; | ||
| import { resolve } from "node:path"; | ||
| import type { FormDefinitionV1 } from "../lib/forms/definition"; | ||
| import { FORM_STARTERS } from "../lib/forms/starters"; | ||
|
|
||
| const runtimeSource = readFileSync(resolve("public/embed/v1.js"), "utf8"); | ||
|
|
||
| const definition: FormDefinitionV1 = { | ||
| version: 1, | ||
| title: "All fields", | ||
| description: "Runtime coverage", | ||
| submitLabel: "Send", | ||
| completion: { type: "message", message: "Thanks" }, | ||
| fields: [ | ||
| { id: "text", key: "text", kind: "text", label: "Text", required: true }, | ||
| { id: "email", key: "email", kind: "email", label: "Email", required: true }, | ||
| { id: "phone", key: "phone", kind: "phone", label: "Phone", required: false }, | ||
| { id: "url", key: "url", kind: "url", label: "URL", required: false }, | ||
| { id: "date", key: "date", kind: "date", label: "Date", required: false }, | ||
| { id: "number", key: "number", kind: "number", label: "Number", required: false }, | ||
| { id: "textarea", key: "textarea", kind: "textarea", label: "Long text", required: false }, | ||
| { id: "select", key: "select", kind: "select", label: "Select", required: false, options: [{ id: "select_a", label: "A", value: "a" }] }, | ||
| { id: "radio", key: "radio", kind: "radio", label: "Radio", required: false, options: [{ id: "radio_a", label: "A", value: "a" }] }, | ||
| { id: "checkbox", key: "checkbox", kind: "checkbox", label: "Checkbox", required: false }, | ||
| { id: "group", key: "group", kind: "checkbox-group", label: "Group", required: false, options: [{ id: "group_a", label: "A", value: "a" }] }, | ||
| { id: "yesno", key: "yesno", kind: "yes-no", label: "Yes or no", required: false }, | ||
| { id: "switch", key: "switch", kind: "switch", label: "Switch", required: false }, | ||
| { id: "slider", key: "slider", kind: "slider", label: "Slider", required: false, validation: { min: 1, max: 10, step: 1 } }, | ||
| ], | ||
| }; | ||
|
|
||
| describe("embed v1 runtime", () => { | ||
| beforeEach(() => { | ||
| document.head.innerHTML = ""; | ||
| document.body.innerHTML = ""; | ||
| delete (window as unknown as { RouterFormsV1?: unknown }).RouterFormsV1; | ||
| window.eval(runtimeSource); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| document.body.innerHTML = ""; | ||
| }); | ||
|
|
||
| it("renders all field kinds with native labels and no framework wrapper", async () => { | ||
| const target = document.createElement("div"); | ||
| document.body.appendChild(target); | ||
| const runtime = (window as unknown as { | ||
| RouterFormsV1: { mount: (target: Element, options: object) => Promise<void> }; | ||
| }).RouterFormsV1; | ||
|
|
||
| await runtime.mount(target, { definition, publicId: "preview", preview: true }); | ||
|
|
||
| expect(target.querySelector("h2")?.textContent).toBe("All fields"); | ||
| expect(target.querySelectorAll("[data-router-field]")).toHaveLength(14); | ||
| expect(target.querySelector('input[type="email"]')).not.toBeNull(); | ||
| expect(target.querySelector('input[type="range"]')).not.toBeNull(); | ||
| expect(target.querySelectorAll("[required]").length).toBeGreaterThan(0); | ||
| expect(target.querySelectorAll("fieldset > legend")).toHaveLength(3); | ||
| expect(target.querySelector("[data-reactroot]")).toBeNull(); | ||
| }); | ||
|
|
||
| it("mounts multiple previews independently and installs scoped styles once", async () => { | ||
| const first = document.createElement("div"); | ||
| const second = document.createElement("div"); | ||
| document.body.append(first, second); | ||
| const runtime = (window as unknown as { | ||
| RouterFormsV1: { mount: (target: Element, options: object) => Promise<void> }; | ||
| }).RouterFormsV1; | ||
|
|
||
| await Promise.all([ | ||
| runtime.mount(first, { definition, publicId: "one", preview: true }), | ||
| runtime.mount(second, { definition, publicId: "two", preview: true }), | ||
| ]); | ||
|
|
||
| expect(first.querySelector("form")).not.toBeNull(); | ||
| expect(second.querySelector("form")).not.toBeNull(); | ||
| expect(document.querySelectorAll("#router-forms-v1-styles")).toHaveLength(1); | ||
| }); | ||
|
|
||
| it("installs runtime styles in an iframe preview document", async () => { | ||
| const iframe = document.createElement("iframe"); | ||
| document.body.appendChild(iframe); | ||
| const iframeDocument = iframe.contentDocument!; | ||
| const target = iframeDocument.createElement("div"); | ||
| iframeDocument.body.appendChild(target); | ||
| const runtime = (window as unknown as { | ||
| RouterFormsV1: { mount: (target: Element, options: object) => Promise<void> }; | ||
| }).RouterFormsV1; | ||
|
|
||
| await runtime.mount(target, { | ||
| definition, | ||
| publicId: "iframe-preview", | ||
| preview: true, | ||
| }); | ||
|
|
||
| expect(target.querySelector("form")).not.toBeNull(); | ||
| expect(iframeDocument.querySelectorAll("#router-forms-v1-styles")).toHaveLength( | ||
| 1 | ||
| ); | ||
| }); | ||
|
|
||
| it("allows any option to satisfy a required checkbox group", async () => { | ||
| const target = document.createElement("div"); | ||
| document.body.appendChild(target); | ||
| const runtime = (window as unknown as { | ||
| RouterFormsV1: { mount: (target: Element, options: object) => Promise<void> }; | ||
| }).RouterFormsV1; | ||
| const groupDefinition: FormDefinitionV1 = { | ||
| ...definition, | ||
| fields: [ | ||
| { | ||
| id: "group", | ||
| key: "group", | ||
| kind: "checkbox-group", | ||
| label: "Group", | ||
| required: true, | ||
| options: [ | ||
| { id: "group_a", label: "A", value: "a" }, | ||
| { id: "group_b", label: "B", value: "b" }, | ||
| ], | ||
| }, | ||
| ], | ||
| }; | ||
|
|
||
| await runtime.mount(target, { | ||
| definition: groupDefinition, | ||
| publicId: "required-group", | ||
| preview: true, | ||
| }); | ||
|
|
||
| const form = target.querySelector("form")!; | ||
| const checkboxes = target.querySelectorAll<HTMLInputElement>('input[type="checkbox"]'); | ||
| checkboxes[1].click(); | ||
| expect(form.checkValidity()).toBe(true); | ||
| }); | ||
|
|
||
| it("uses unique control IDs when the same form is mounted twice", async () => { | ||
| const first = document.createElement("div"); | ||
| const second = document.createElement("div"); | ||
| document.body.append(first, second); | ||
| const runtime = (window as unknown as { | ||
| RouterFormsV1: { mount: (target: Element, options: object) => Promise<void> }; | ||
| }).RouterFormsV1; | ||
|
|
||
| await Promise.all([ | ||
| runtime.mount(first, { definition, publicId: "duplicate", preview: true }), | ||
| runtime.mount(second, { definition, publicId: "duplicate", preview: true }), | ||
| ]); | ||
|
|
||
| const ids = Array.from(document.querySelectorAll<HTMLElement>("[id]")) | ||
| .map((element) => element.id) | ||
| .filter((id) => id !== "router-forms-v1-styles"); | ||
| expect(new Set(ids).size).toBe(ids.length); | ||
| }); | ||
|
|
||
| it.each(Object.entries(FORM_STARTERS))( | ||
| "renders the %s starter through the production runtime", | ||
| async (_starterId, starter) => { | ||
| const target = document.createElement("div"); | ||
| document.body.appendChild(target); | ||
| const runtime = (window as unknown as { | ||
| RouterFormsV1: { | ||
| mount: (target: Element, options: object) => Promise<void>; | ||
| }; | ||
| }).RouterFormsV1; | ||
|
|
||
| await runtime.mount(target, { | ||
| definition: starter, | ||
| publicId: `starter-${_starterId}`, | ||
| preview: true, | ||
| }); | ||
|
|
||
| expect(target.querySelector("form")).not.toBeNull(); | ||
| expect(target.querySelectorAll("[data-router-field]")).toHaveLength( | ||
| starter.fields.length | ||
| ); | ||
| } | ||
| ); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
sed -n '1,95p' .github/workflows/ci.ymlRepository: 9d8dev/router
Length of output: 2348
🌐 Web query:
actions/checkout v4 persist-credentials false README credentials persisted local git config💡 Result:
In the actions/checkout action (including v4), the persist-credentials input determines whether the authentication token (or SSH key) used to fetch the repository is configured in the local Git configuration [1][2][3]. By default, persist-credentials is set to true [1][2]. When enabled, the action adds the credentials to the repository's local.git/config file (often via an http.extraheader) [1][4][5]. This allows subsequent steps in the same job to perform authenticated Git operations without needing to re-provide the token [1][3]. The action removes these credentials during the post-job cleanup [1][2][3]. Setting persist-credentials: false prevents the action from writing these credentials to the local Git configuration [1][6]. This is a recommended security best practice for workflows that do not require the ability to push commits or perform other authenticated Git operations, as it prevents other steps or third-party actions within the same job from potentially accessing or misusing the token [4][6][5][7]. Summary of behavior: - Default (true): Credentials are written to.git/config during checkout and removed during post-job cleanup [1][2]. - persist-credentials: false: Credentials are never written to the local Git configuration [1][6].
Citations:
Sensitive Data Exposure (CWE-522): Insufficiently Protected Credentials
Reachability: External · Exploitability: Moderate
Disable GitHub token persistence for all checkouts.
These jobs run pull-request-controlled code. Add
persist-credentials: falseto all threeactions/checkout@v4steps to preventGITHUB_TOKENfrom being written to local Git configuration.🧰 Tools
🪛 zizmor (1.29.0)
[warning] 12-12: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false
(artipacked)
[warning] 1-80: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block
(excessive-permissions)
[warning] 9-29: overly broad permissions (excessive-permissions): default permissions used due to no permissions: block
(excessive-permissions)
🤖 Prompt for AI Agents
Source: Linters/SAST tools