Skip to content

feat: add applyInstantJson build action for form filling#14

Open
jdrhyne wants to merge 2 commits intomainfrom
feat/apply-instant-json
Open

feat: add applyInstantJson build action for form filling#14
jdrhyne wants to merge 2 commits intomainfrom
feat/apply-instant-json

Conversation

@jdrhyne
Copy link
Contributor

@jdrhyne jdrhyne commented Feb 5, 2026

Summary

Adds the applyInstantJson build action for PDF form filling and annotation import.

Changes

Schema:

  • ApplyInstantJsonActionSchema — applies Instant JSON to documents for:
    • Filling PDF form fields
    • Creating form fields
    • Importing annotations
  • Added to BuildActionSchema discriminated union

Tests:

  • Schema validation test (valid input)
  • Schema rejection test (missing file property)

Testing

  • Build compiles clean
  • 42 tests passing (2 new tests)

Documentation

See Instant JSON documentation for format details.


Split from #12 per review feedback to keep PRs focused and reviewable.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for the applyInstantJson build action, which enables PDF form filling and annotation import using Nutrient's Instant JSON format. This is a focused PR split from #12 to keep changes reviewable.

Changes:

  • Added ApplyInstantJsonActionSchema to define the new action type with validation
  • Added schema to BuildActionSchema discriminated union to make it available
  • Added two unit tests for schema validation (valid and invalid inputs)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/schemas.ts Defines ApplyInstantJsonActionSchema following the same pattern as ApplyXfdfActionSchema, and adds it to the BuildActionSchema union
tests/unit.test.ts Adds unit tests for schema validation of the new applyInstantJson action type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +164 to +177
export const ApplyInstantJsonActionSchema = z.object({
type: z
.literal('applyInstantJson')
.describe(
'Apply Instant JSON to the document. Used for filling PDF form fields, creating form fields, ' +
'and importing annotations. The file should be in Nutrient Instant JSON format.',
),
file: z
.string()
.describe(
'The path to the Instant JSON file or a reference to a file in the multipart request. ' +
'Resolves to sandbox path if enabled, otherwise resolves to the local file system.',
),
})
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

The schema is correctly defined and follows the same pattern as ApplyXfdfActionSchema. However, the implementation is incomplete. The src/dws/build.ts file needs to be updated to handle applyInstantJson actions with local file references. Without this update, applyInstantJson will only work with URLs, not local files. The processActionFileReferences function in build.ts should include a condition similar to the one for applyXfdf to process the file reference.

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +54
describe('BuildActionSchema', () => {
it('should parse applyInstantJson actions', () => {
const result = BuildActionSchema.safeParse({ type: 'applyInstantJson', file: '/test.json' })

expect(result.success).toBe(true)
})

it('should reject applyInstantJson actions without a file', () => {
const result = BuildActionSchema.safeParse({ type: 'applyInstantJson' })

expect(result.success).toBe(false)
})
})
Copy link

Copilot AI Feb 5, 2026

Choose a reason for hiding this comment

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

Consider adding an integration test example following the pattern established for other build actions. The tests/build-api-examples.ts file contains examples for all other build actions (e.g., applyXfdfExample at line 273). Adding an applyInstantJsonExample would provide better test coverage and serve as documentation for users of this feature.

Copilot uses AI. Check for mistakes.
@jdrhyne
Copy link
Contributor Author

jdrhyne commented Feb 6, 2026

Addressed both Copilot review comments in 96f4fe4:

  1. src/dws/build.ts — Added applyInstantJson handling in processActionFileReferences following the same pattern as applyXfdf, so local file references work correctly.

  2. tests/build-api-examples.ts — Added applyInstantJsonExample following the established pattern of other build action examples.

Build compiles clean, all tests passing.

@jdrhyne jdrhyne requested a review from nickwinder February 6, 2026 16:32
Comment on lines 87 to +94
} else if (action.type === 'applyXfdf' && 'file' in action && typeof action.file === 'string') {
const fileReference = await processFileReference(action.file)
action.file = fileReference.key
return fileReference
} else if (action.type === 'applyInstantJson' && 'file' in action && typeof action.file === 'string') {
const fileReference = await processFileReference(action.file)
action.file = fileReference.key
return fileReference
Copy link
Collaborator

Choose a reason for hiding this comment

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

Come on AI. super obvious duplication here. :)

- Add ApplyInstantJsonActionSchema for PDF form filling, form field creation, and annotation import
- Include schema in BuildActionSchema discriminated union
- Add unit tests for schema validation (valid input, missing file rejection)
@jdrhyne jdrhyne force-pushed the feat/apply-instant-json branch from 96f4fe4 to 13571c2 Compare February 7, 2026 21:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants