Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/dws/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ async function processActionFileReferences(action: Action): Promise<FileReferenc
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
}

// No need to parse files for the other actions
Expand Down
18 changes: 16 additions & 2 deletions src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,21 @@ export const ApplyXfdfActionSchema = z.object({
),
})

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.',
),
})
Comment on lines +200 to +213
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.

export const FlattenActionSchema = z.object({
type: z.literal('flatten').describe('Flatten the annotations in the document.'),

Expand Down Expand Up @@ -359,8 +374,7 @@ export const ApplyRedactionsActionSchema = z.object({
})

export const BuildActionSchema = z.discriminatedUnion('type', [
// For now, we will not support applying Instant JSON.
// ApplyInstantJsonActionSchema,
ApplyInstantJsonActionSchema,
ApplyXfdfActionSchema,
FlattenActionSchema,
OcrActionSchema,
Expand Down
21 changes: 21 additions & 0 deletions tests/build-api-examples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,27 @@ export const applyXfdfExample: BuildAPIArgs = {
outputPath: 'output_pdf.pdf',
}

// Example with applying Instant JSON
export const applyInstantJsonExample: BuildAPIArgs = {
instructions: {
parts: [
{
file: 'example.pdf',
},
],
actions: [
{
type: 'applyInstantJson',
file: 'example.json',
},
],
output: {
type: 'pdf',
},
},
outputPath: 'output_pdf.pdf',
}

// Example with redactions using preset
export const redactionsPresetExample: BuildAPIArgs = {
instructions: {
Expand Down
16 changes: 15 additions & 1 deletion tests/unit.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import fs, { Stats } from 'fs'
import { Readable } from 'stream'
import { AiRedactArgsSchema, Instructions, SignatureOptions } from '../src/schemas.js'
import { AiRedactArgsSchema, BuildActionSchema, Instructions, SignatureOptions } from '../src/schemas.js'
import { config as dotenvConfig } from 'dotenv'
import { performBuildCall } from '../src/dws/build.js'
import { performSignCall } from '../src/dws/sign.js'
Expand Down Expand Up @@ -40,6 +40,20 @@ function createMockStream(content: string | Buffer): Readable {
return readable
}

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)
})
})
Comment on lines +43 to +55
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.

describe('API Functions', () => {
const originalEnv = process.env

Expand Down