feat: add applyInstantJson build action for form filling#14
feat: add applyInstantJson build action for form filling#14
Conversation
There was a problem hiding this comment.
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
ApplyInstantJsonActionSchemato define the new action type with validation - Added schema to
BuildActionSchemadiscriminated 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.
| 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.', | ||
| ), | ||
| }) |
There was a problem hiding this comment.
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.
| 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) | ||
| }) | ||
| }) |
There was a problem hiding this comment.
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.
|
Addressed both Copilot review comments in 96f4fe4:
Build compiles clean, all tests passing. |
| } 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 |
There was a problem hiding this comment.
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)
96f4fe4 to
13571c2
Compare
Summary
Adds the
applyInstantJsonbuild action for PDF form filling and annotation import.Changes
Schema:
ApplyInstantJsonActionSchema— applies Instant JSON to documents for:BuildActionSchemadiscriminated unionTests:
fileproperty)Testing
Documentation
See Instant JSON documentation for format details.
Split from #12 per review feedback to keep PRs focused and reviewable.