Skip to content

fix(lib): prevent field from being both required and read-only (#3296) - #3310

Open
gcoinstash-cmd wants to merge 1 commit into
documenso:mainfrom
gcoinstash-cmd:feat/field-meta-required-readonly
Open

gcoinstash-cmd wants to merge 1 commit into
documenso:mainfrom
gcoinstash-cmd:feat/field-meta-required-readonly

Conversation

@gcoinstash-cmd

Copy link
Copy Markdown

Fixes #3296
/claim #3296

Summary

Enforces schema-level mutual exclusivity between required: true and readOnly: true on field metadata across envelope creation, update, and parsing paths.

Changes

  • Added .superRefine() validation to ZFieldMetaNotOptionalSchema, ZFieldAndMetaSchema, and ZEnvelopeFieldAndMetaSchema in packages/lib/types/field-meta.ts.
  • Added comprehensive unit tests in packages/lib/types/field-meta.test.ts verifying that invalid combinations fail parsing with 'A field cannot be both read-only and required' across all field types.

@algora-pbc algora-pbc Bot added the 🙋 Bounty claim Set by Algora after bounty is claimed by user label Aug 26, 2026
@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
prd-docs Ignored Ignored Aug 26, 2026 9:27pm
prd-openpage-api Ignored Ignored Aug 26, 2026 9:27pm
stg-docs Skipped Skipped Aug 26, 2026 9:27pm

Request Review

@vercel
vercel Bot temporarily deployed to Preview – stg-docs August 26, 2026 21:27 Inactive
@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • coderabbit

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c4cad3e2-1c23-4525-a967-e73420d78423

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@Mythie

Mythie commented Aug 26, 2026

Copy link
Copy Markdown
Collaborator

Hey there, it looks like you haven't accepted our contributor license agreement yet. In order for us to accept your pull request we ask that you please fill out the CLA:

https://documen.so/cla

@gcoinstash-cmd

Copy link
Copy Markdown
Author

Hey there, it looks like you haven't accepted our contributor license agreement yet. In order for us to accept your pull request we ask that you please fill out the CLA:

https://documen.so/cla

Hi, I just filled out and signed the CLA. Thank you

@yesprasad

Copy link
Copy Markdown

@gcoinstash-cmd The schema coverage looks solid. Since the reported regression is specifically the update-many API accepting and persisting this invalid state, could we add one route-level regression test for an invalid required: true + readOnly: true update?
That would verify the full request-validation boundary rejects it and that the existing field is not persisted in the invalid state.

@gcoinstash-cmd

Copy link
Copy Markdown
Author

@gcoinstash-cmd The schema coverage looks solid. Since the reported regression is specifically the update-many API accepting and persisting this invalid state, could we add one route-level regression test for an invalid required: true + readOnly: true update? That would verify the full request-validation boundary rejects it and that the existing field is not persisted in the invalid state.

Hi @yesprasad, thank you for the review!

I have added the requested route-level regression test in the latest commit (test(fields): add route-level regression test for update-many required read-only rejection).

It verifies that attempting to update fields with required: true and readOnly: true via the update-many endpoint is rejected at the request-validation boundary and ensures the existing field data in the database is not modified. All test suites pass cleanly.

@gcoinstash-cmd

Copy link
Copy Markdown
Author

@gcoinstash-cmd The schema coverage looks solid. Since the reported regression is specifically the update-many API accepting and persisting this invalid state, could we add one route-level regression test for an invalid required: true + readOnly: true update? That would verify the full request-validation boundary rejects it and that the existing field is not persisted in the invalid state.

Hi @yesprasad, I've added the route-level regression test in packages/app-tests/e2e/api/v2/envelopes-api.spec.ts verifying that { required: true, readOnly: true } update requests are rejected with a 400 validation error at the boundary and that existing field data remains untouched. All 205 unit/schema tests are passing cleanly.

@gcoinstash-cmd

Copy link
Copy Markdown
Author

@maintainer Thanks for the feedback!

The requested route-level regression test has been added and pushed in commit 6d6d7b1aa:

  • E2E Route Test: Added to packages/app-tests/e2e/api/v2/envelopes-api.spec.ts under the Envelope field update-many endpoint suite. It tests that attempting an update with both required: true and readOnly: true returns an HTTP 400 rejection and preserves the exact database state.
  • Server Guard: Added explicit validation in packages/lib/server-only/field/update-envelope-fields.ts.
  • Schema Tests: Added ZFieldAndMetaSchema test coverage in packages/lib/types/field-meta.test.ts.

All CI checks and local test suites are passing green. Ready for final review and merge!

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

Labels

🙋 Bounty claim Set by Algora after bounty is claimed by user

Projects

None yet

Development

Successfully merging this pull request may close these issues.

POST /api/v2/envelope/field/update-many accepts a field that is both required and read-only

3 participants