From 2f53d43bd39f77e0f34d79fff261a16b1c9106b7 Mon Sep 17 00:00:00 2001 From: Daniel Naab Date: Thu, 21 Mar 2024 10:07:41 -0500 Subject: [PATCH 1/5] Stub out a FormBuilder class --- .../src/__tests__/doj-pardon-marijuana.test.ts | 3 ++- packages/forms/src/builder/index.ts | 13 +++++++++++++ packages/forms/src/index.ts | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 packages/forms/src/builder/index.ts diff --git a/packages/documents/src/__tests__/doj-pardon-marijuana.test.ts b/packages/documents/src/__tests__/doj-pardon-marijuana.test.ts index c1d41564..7b5d4a1d 100644 --- a/packages/documents/src/__tests__/doj-pardon-marijuana.test.ts +++ b/packages/documents/src/__tests__/doj-pardon-marijuana.test.ts @@ -3,10 +3,11 @@ import { describe, expect, it } from 'vitest'; import { loadSamplePDF } from './sample-data'; import { fillPDF, getDocumentFieldData } from '../pdf'; import { Success } from '@atj/common'; -import { DocumentFieldMap } from '@atj/forms'; +import { DocumentFieldMap, FormBuilder } from '@atj/forms'; describe('DOJ Pardon Office marijuana pardon application form', () => { it('produces valid PDF from imported PDF', async () => { + const builder = new FormBuilder(); const pdfBytes = await loadSamplePDF( 'doj-pardon-marijuana/application_for_certificate_of_pardon_for_simple_marijuana_possession.pdf' ); diff --git a/packages/forms/src/builder/index.ts b/packages/forms/src/builder/index.ts new file mode 100644 index 00000000..e2cdbdbe --- /dev/null +++ b/packages/forms/src/builder/index.ts @@ -0,0 +1,13 @@ +import { nullFormDefinition, type FormDefinition } from '..'; + +export class FormBuilder { + form: FormDefinition; + + constructor(initialForm: FormDefinition = nullFormDefinition) { + this.form = initialForm || nullFormDefinition; + } + + async addDocument(fileDetails: { name: string; data: Uint8Array }) { + //this.form = await addDocument(this.form, fileDetails); + } +} diff --git a/packages/forms/src/index.ts b/packages/forms/src/index.ts index 81c9cdf9..32fdbedb 100644 --- a/packages/forms/src/index.ts +++ b/packages/forms/src/index.ts @@ -11,6 +11,7 @@ import { getFormElementConfig, } from './element'; +export * from './builder'; export * from './config'; export * from './documents'; export * from './element'; From 7bfa14c42286d6ea383c0c1a95d446d38e9a22cd Mon Sep 17 00:00:00 2001 From: Daniel Naab Date: Thu, 21 Mar 2024 10:39:44 -0500 Subject: [PATCH 2/5] Merge @atj/documents into the @atj/forms package. Context: working on FormBuilder, we need to centralize document handling. Documents was prematurely split off, before the interface between it and forms core was worked out. We will likely split off PDF-specific handling into an adapter in the near future, but it will have a different shape than @atj/documents. --- apps/doj-demo/package.json | 1 - apps/spotlight/package.json | 1 - apps/spotlight/public/sample-documents | 2 +- packages/design/package.json | 1 - .../FormManager/DocumentImporter/index.tsx | 8 +- .../FormList/PDFFileSelect/hooks.ts | 9 +- .../FormList/PDFFileSelect/index.tsx | 2 +- .../src/experiments/document-assembler.tsx | 3 +- packages/docassemble/package.json | 2 +- packages/documents/.gitignore | 1 - packages/documents/README.md | 3 - packages/documents/package.json | 22 - packages/documents/src/index.ts | 18 - .../documents/src/pdf/al_name_change.json | 1006 ----------------- packages/documents/tsconfig.json | 11 - packages/documents/vitest.config.ts | 5 - packages/form-service/package.json | 1 - .../src/operations/submit-form.ts | 9 +- packages/forms/package.json | 1 + .../alabama-name-change/ps-12.pdf | Bin .../ca-unlawful-detainer/README.md | 0 .../ca-unlawful-detainer/pos030.pdf | Bin .../ca-unlawful-detainer/ud-105.fields.json | 0 .../ca-unlawful-detainer/ud105.pdf | Bin .../sample-documents}/dod_character.pdf | Bin .../doj-pardon-marijuana/README.md | 0 ...pardon_for_simple_marijuana_possession.pdf | Bin .../__tests__/doj-pardon-marijuana.test.ts | 6 +- .../src/documents}/__tests__/dummy.test.ts | 0 .../src/documents}/__tests__/extract.test.ts | 0 .../src/documents}/__tests__/fill-pdf.test.ts | 3 +- .../src/documents}/__tests__/sample-data.ts | 2 +- .../documents}/__tests__/suggestions.test.ts | 0 .../src => forms/src/documents}/document.ts | 7 +- packages/forms/src/documents/index.ts | 70 +- .../forms/src/documents/pdf/al_name_change.ts | 869 ++++++++++++++ .../src/documents}/pdf/extract.ts | 2 +- .../src/documents}/pdf/generate-dummy.ts | 0 .../src/documents}/pdf/generate.ts | 4 +- .../src => forms/src/documents}/pdf/index.ts | 0 .../src/documents}/pdf/mock-api.ts | 14 +- .../src/documents}/suggestions.ts | 0 packages/forms/src/documents/types.ts | 53 + .../src => forms/src/documents}/util.ts | 0 packages/forms/src/index.ts | 2 +- pnpm-lock.yaml | 56 +- tsconfig.json | 10 - 47 files changed, 993 insertions(+), 1211 deletions(-) delete mode 100644 packages/documents/.gitignore delete mode 100644 packages/documents/README.md delete mode 100644 packages/documents/package.json delete mode 100644 packages/documents/src/index.ts delete mode 100644 packages/documents/src/pdf/al_name_change.json delete mode 100644 packages/documents/tsconfig.json delete mode 100644 packages/documents/vitest.config.ts rename packages/{documents/samples => forms/sample-documents}/alabama-name-change/ps-12.pdf (100%) rename packages/{documents/samples => forms/sample-documents}/ca-unlawful-detainer/README.md (100%) rename packages/{documents/samples => forms/sample-documents}/ca-unlawful-detainer/pos030.pdf (100%) rename packages/{documents/samples => forms/sample-documents}/ca-unlawful-detainer/ud-105.fields.json (100%) rename packages/{documents/samples => forms/sample-documents}/ca-unlawful-detainer/ud105.pdf (100%) rename packages/{documents/samples => forms/sample-documents}/dod_character.pdf (100%) rename packages/{documents/samples => forms/sample-documents}/doj-pardon-marijuana/README.md (100%) rename packages/{documents/samples => forms/sample-documents}/doj-pardon-marijuana/application_for_certificate_of_pardon_for_simple_marijuana_possession.pdf (100%) rename packages/{documents/src => forms/src/documents}/__tests__/doj-pardon-marijuana.test.ts (95%) rename packages/{documents/src => forms/src/documents}/__tests__/dummy.test.ts (100%) rename packages/{documents/src => forms/src/documents}/__tests__/extract.test.ts (100%) rename packages/{documents/src => forms/src/documents}/__tests__/fill-pdf.test.ts (99%) rename packages/{documents/src => forms/src/documents}/__tests__/sample-data.ts (85%) rename packages/{documents/src => forms/src/documents}/__tests__/suggestions.test.ts (100%) rename packages/{documents/src => forms/src/documents}/document.ts (96%) create mode 100644 packages/forms/src/documents/pdf/al_name_change.ts rename packages/{documents/src => forms/src/documents}/pdf/extract.ts (96%) rename packages/{documents/src => forms/src/documents}/pdf/generate-dummy.ts (100%) rename packages/{documents/src => forms/src/documents}/pdf/generate.ts (96%) rename packages/{documents/src => forms/src/documents}/pdf/index.ts (100%) rename packages/{documents/src => forms/src/documents}/pdf/mock-api.ts (96%) rename packages/{documents/src => forms/src/documents}/suggestions.ts (100%) create mode 100644 packages/forms/src/documents/types.ts rename packages/{documents/src => forms/src/documents}/util.ts (100%) diff --git a/apps/doj-demo/package.json b/apps/doj-demo/package.json index 91d9be94..852231e8 100644 --- a/apps/doj-demo/package.json +++ b/apps/doj-demo/package.json @@ -14,7 +14,6 @@ "@astrojs/node": "^8.2.3", "@astrojs/react": "^3.0.9", "@atj/design": "workspace:*", - "@atj/documents": "workspace:*", "@atj/form-service": "workspace:*", "@atj/forms": "workspace:*", "astro": "^4.4.11", diff --git a/apps/spotlight/package.json b/apps/spotlight/package.json index 2527ac40..b9e3e257 100644 --- a/apps/spotlight/package.json +++ b/apps/spotlight/package.json @@ -12,7 +12,6 @@ "dependencies": { "@astrojs/react": "^3.0.9", "@atj/design": "workspace:*", - "@atj/documents": "workspace:*", "@atj/form-service": "workspace:*", "@atj/forms": "workspace:*", "astro": "^4.3.3", diff --git a/apps/spotlight/public/sample-documents b/apps/spotlight/public/sample-documents index d48f4bfb..edc7ca95 120000 --- a/apps/spotlight/public/sample-documents +++ b/apps/spotlight/public/sample-documents @@ -1 +1 @@ -../../../packages/documents/samples \ No newline at end of file +../../../packages/forms/sample-documents \ No newline at end of file diff --git a/packages/design/package.json b/packages/design/package.json index 41f5d003..c987b4dc 100644 --- a/packages/design/package.json +++ b/packages/design/package.json @@ -62,7 +62,6 @@ }, "dependencies": { "@atj/common": "workspace:*", - "@atj/documents": "workspace:*", "@atj/form-service": "workspace:*", "@atj/forms": "workspace:*", "@dnd-kit/core": "^6.1.0", diff --git a/packages/design/src/FormManager/DocumentImporter/index.tsx b/packages/design/src/FormManager/DocumentImporter/index.tsx index 69a19df6..733f64e7 100644 --- a/packages/design/src/FormManager/DocumentImporter/index.tsx +++ b/packages/design/src/FormManager/DocumentImporter/index.tsx @@ -2,16 +2,14 @@ import React, { PropsWithChildren, useReducer } from 'react'; import { useNavigate } from 'react-router-dom'; import { + type DocumentFieldMap, + type FormDefinition, SAMPLE_DOCUMENTS, addDocument, addDocumentFieldsToForm, -} from '@atj/documents'; -import { type FormService } from '@atj/form-service'; -import { - type DocumentFieldMap, - type FormDefinition, createFormSession, } from '@atj/forms'; +import { type FormService } from '@atj/form-service'; import Form, { FormUIContext } from '../../Form'; import { onFileInputChangeGetFile } from '../FormList/PDFFileSelect/file-input'; diff --git a/packages/design/src/FormManager/FormList/PDFFileSelect/hooks.ts b/packages/design/src/FormManager/FormList/PDFFileSelect/hooks.ts index b3b8bcc8..6ffed12c 100644 --- a/packages/design/src/FormManager/FormList/PDFFileSelect/hooks.ts +++ b/packages/design/src/FormManager/FormList/PDFFileSelect/hooks.ts @@ -1,10 +1,13 @@ import { useNavigate } from 'react-router-dom'; import { type Result } from '@atj/common'; -import { addDocument } from '@atj/documents'; -import { FormElement, createForm } from '@atj/forms'; +import { + type FormElement, + type FormSummary, + addDocument, + createForm, +} from '@atj/forms'; import { type FormService } from '@atj/form-service'; -import { FormSummary } from '@atj/forms/src/config/elements/form-summary'; export const useDocumentImporter = ( formService: FormService, diff --git a/packages/design/src/FormManager/FormList/PDFFileSelect/index.tsx b/packages/design/src/FormManager/FormList/PDFFileSelect/index.tsx index 26a054cb..3dfa6f24 100644 --- a/packages/design/src/FormManager/FormList/PDFFileSelect/index.tsx +++ b/packages/design/src/FormManager/FormList/PDFFileSelect/index.tsx @@ -1,6 +1,6 @@ import React from 'react'; -import { SAMPLE_DOCUMENTS } from '@atj/documents'; +import { SAMPLE_DOCUMENTS } from '@atj/forms'; import { FormService } from '@atj/form-service'; import { onFileInputChangeGetFile } from './file-input'; diff --git a/packages/design/src/experiments/document-assembler.tsx b/packages/design/src/experiments/document-assembler.tsx index 85333623..3ced7501 100644 --- a/packages/design/src/experiments/document-assembler.tsx +++ b/packages/design/src/experiments/document-assembler.tsx @@ -1,5 +1,6 @@ import React, { useState } from 'react'; -import { generateDummyPDF } from '@atj/documents'; + +import { generateDummyPDF } from '@atj/forms'; export const downloadPdfBytes = (bytes: Uint8Array) => { const base64 = btoa(String.fromCharCode(...bytes)); diff --git a/packages/docassemble/package.json b/packages/docassemble/package.json index 6ef28338..ce525e71 100644 --- a/packages/docassemble/package.json +++ b/packages/docassemble/package.json @@ -11,7 +11,7 @@ "test:integration": "vitest run --coverage" }, "dependencies": { - "@atj/documents": "workspace:*" + "@atj/forms": "workspace:*" }, "devDependencies": { "@vitest/coverage-v8": "^0.34.6", diff --git a/packages/documents/.gitignore b/packages/documents/.gitignore deleted file mode 100644 index 849ddff3..00000000 --- a/packages/documents/.gitignore +++ /dev/null @@ -1 +0,0 @@ -dist/ diff --git a/packages/documents/README.md b/packages/documents/README.md deleted file mode 100644 index 51f69014..00000000 --- a/packages/documents/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# @atj/documents - -Document generation. diff --git a/packages/documents/package.json b/packages/documents/package.json deleted file mode 100644 index 1e22a5af..00000000 --- a/packages/documents/package.json +++ /dev/null @@ -1,22 +0,0 @@ -{ - "name": "@atj/documents", - "version": "1.0.0", - "description": "10x ATJ document generation", - "type": "module", - "license": "CC0", - "main": "src/index.ts", - "scripts": { - "build": "tsup src/* --env.NODE_ENV production", - "dev": "tsup src/* --watch", - "test": "vitest run --coverage" - }, - "dependencies": { - "@atj/common": "workspace:*", - "@atj/forms": "workspace:*", - "pdf-lib": "^1.17.1", - "zod": "^3.22.4" - }, - "devDependencies": { - "@types/node": "^20.10.4" - } -} diff --git a/packages/documents/src/index.ts b/packages/documents/src/index.ts deleted file mode 100644 index 0ce1b259..00000000 --- a/packages/documents/src/index.ts +++ /dev/null @@ -1,18 +0,0 @@ -export * from './document'; -export * from './pdf'; -export * from './suggestions'; - -export const SAMPLE_DOCUMENTS = [ - { - path: 'sample-documents/ca-unlawful-detainer/ud105.pdf', - title: 'California UD-105 (unlawful detainer)', - }, - { - path: 'sample-documents/alabama-name-change/ps-12.pdf', - title: 'Alabama PS-12 (name change)', - }, - { - path: 'sample-documents/doj-pardon-marijuana/application_for_certificate_of_pardon_for_simple_marijuana_possession.pdf', - title: 'DOJ Marijuana Pardon Application', - }, -]; diff --git a/packages/documents/src/pdf/al_name_change.json b/packages/documents/src/pdf/al_name_change.json deleted file mode 100644 index 9eab61c5..00000000 --- a/packages/documents/src/pdf/al_name_change.json +++ /dev/null @@ -1,1006 +0,0 @@ -{ - "raw_text": "Request to Change Name", - "title": "Request to Change Name (For An Adult)", - "description": "", - "elements": [ - { - "id": "1fc0b74a-7139-46a7-9aad-8e3e3ff94a6d", - "group_id": 2, - "element_type": "text", - "element_params": { - "text": "In the Probate Court of (county): ", - "text_style": "JTUTCJ+ArialMT 9.840000000000032", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "County_Name1", - "placeholder": "", - "instructions": "Type name of Alabama county where you live", - "required": false, - "options": [] - } - } - ], - "parent": null - }, - { - "id": "6904a3ef-17f6-4a1b-83c7-4a963f1a43c5", - "group_id": 3, - "element_type": "text", - "element_params": { - "text": "Your current name", - "text_style": "JTUTCJ+ArialMT 9.840000000000032", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Current_First_Name1", - "placeholder": "", - "instructions": "Type your current first name", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Current_Middle_Name1", - "placeholder": "", - "instructions": "Type your current middle name", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Current_Last_Name1", - "placeholder": "", - "instructions": "Type your current last name", - "required": false, - "options": [] - } - } - ], - "parent": null - }, - { - "id": "0a10d256-c938-4c83-9045-8f31df99bbff", - "group_id": 5, - "element_type": "text", - "element_params": { - "text": "To ask the court to change your name, you must fill out this form, and: ", - "text_style": "subheading", - "options": null - }, - "inputs": [], - "parent": null - }, - { - "id": "9ffecb48-b274-44a9-ab21-17f90db129ca", - "group_id": 6, - "element_type": "text", - "element_params": { - "text": "Attach a certified copy of your birth certificate and a copy of your photo ID, and ", - "text_style": "indent", - "options": null - }, - "inputs": [], - "parent": null - }, - { - "id": "21ce04d1-7d40-40c9-bdd5-e738b801a6d3", - "group_id": 7, - "element_type": "text", - "element_params": { - "text": " File your form and attachments in the same county where you live. ", - "text_style": "indent", - "options": null - }, - "inputs": [], - "parent": null - }, - { - "id": "fd565668-436f-42f3-9969-4de1b86db4ae", - "group_id": 8, - "element_type": "text", - "element_params": { - "text": "I declare that the following information is true: ", - "text_style": "subheading", - "options": null - }, - "inputs": [], - "parent": null - }, - { - "id": "767b5b4e-f1f0-4ca2-a606-d74562d4b78b", - "group_id": 9, - "element_type": "text", - "element_params": { - "text": "My current name", - "text_style": "JTUTCJ+ArialMT 8.879999999999995", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Current_First_Name2", - "placeholder": "", - "instructions": "Type your current first name", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Current_Middle_Name2", - "placeholder": "", - "instructions": "Type your current middle name", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Current_Last_Name2", - "placeholder": "", - "instructions": "Type your current last name", - "required": false, - "options": [] - } - } - ], - "parent": null - }, - { - "id": "91955d9c-b3fc-4190-b1fd-bfddd49a2a6c", - "group_id": 11, - "element_type": "text", - "element_params": { - "text": "My address", - "text_style": "JTUTCJ+ArialMT 8.879999999999995", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Street_Address", - "placeholder": "", - "instructions": "Type your street address", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "City", - "placeholder": "", - "instructions": "Type the name of your city", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "State", - "placeholder": "", - "instructions": "Type the state where you live", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Zip", - "placeholder": "", - "instructions": "Type your zip code", - "required": false, - "options": [] - } - } - ], - "parent": null - }, - { - "id": "7ce2801f-022d-4140-b004-fdcdaf9a0767", - "group_id": 13, - "element_type": "text", - "element_params": { - "text": "My phone numbers", - "text_style": "DURMBL+Arial-BoldMT 8.879999999999995", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Home_Phone", - "placeholder": "", - "instructions": "Type your home phone number including area code", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Work_Phone", - "placeholder": "", - "instructions": "Type your work phone number including area code", - "required": false, - "options": [] - } - } - ], - "parent": null - }, - { - "id": "c3212cab-6019-4e60-8198-f11b87c81e82", - "group_id": 14, - "element_type": "text", - "element_params": { - "text": "My date of birth is (mm/dd/yyyy): ", - "text_style": "JTUTCJ+ArialMT 8.879999999999995", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "DOB", - "placeholder": "", - "instructions": "Type your date of birth as mm/dd/yyyy", - "required": false, - "options": [] - } - } - ], - "parent": null - }, - { - "id": "ce713b94-0008-43ab-ace4-6b38d01b2f76", - "group_id": 15, - "element_type": "text", - "element_params": { - "text": "My name at birth", - "text_style": "JTUTCJ+ArialMT 8.879999999999995", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Birth_First_Name", - "placeholder": "", - "instructions": "Type the first name you were given at birth", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Birth_Middle_Name", - "placeholder": "", - "instructions": "Type the middle name you were given at birth", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Birth_Last_Name", - "placeholder": "", - "instructions": "Type the last name you were given at birth", - "required": false, - "options": [] - } - } - ], - "parent": null - }, - { - "id": "f228e971-d4db-43f6-a03b-4eb009f214b0", - "group_id": 17, - "element_type": "text", - "element_params": { - "text": "I am an adult (19 or older), of sound mind, and live in (name of Alabama county): ", - "text_style": "LEDWHU+TimesNewRomanPSMT 8.879999999999995", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "County_Name2", - "placeholder": "", - "instructions": "Type the name of the county where you live now", - "required": false, - "options": [] - } - } - ], - "parent": null - }, - { - "id": "dcb5d901-a293-4f53-b663-a4d401af0812", - "group_id": 18, - "element_type": "text", - "element_params": { - "text": "The attached copy of my photo ID is my (choose one):", - "text_style": "heading", - "options": null - }, - "inputs": [], - "parent": "PhotoID" - }, - { - "id": "dcb5d901-a293-4f53-b663-a4d401ac0812", - "group_id": 18, - "element_type": "text", - "element_params": { - "text": "Driver\u2019s license, # ", - "text_style": "JTUTCJ+ArialMT 12.0", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "DL#", - "placeholder": "", - "instructions": "Type your driver's license number", - "required": false, - "options": [] - } - } - ], - "parent": "PhotoID" - }, - { - "id": "1a8cbd28-f600-47f8-9ce0-85ae136ba338", - "group_id": 18, - "element_type": "text", - "element_params": { - "text": "Non-driver\u2019s photo, ID #: ", - "text_style": "JTUTCJ+ArialMT 8.879999999999995", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "ID#", - "placeholder": "", - "instructions": "Type the number from your photo ID (not driver's license)", - "required": false, - "options": [] - } - } - ], - "parent": "PhotoID" - }, - { - "id": "a532ebcf-b71a-4135-9de1-819bc98815b0", - "group_id": 19, - "element_type": "text", - "element_params": { - "text": "I ask the court to change my name because (explain why you want to change your name): ", - "text_style": "LEDWHU+TimesNewRomanPSMT 8.879999999999995", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "Why_change_name1", - "placeholder": "", - "instructions": "Type why you want to change your name", - "required": false, - "options": [] - } - } - ], - "parent": null - }, - { - "id": "f21048d9-95f4-4e83-843b-cf8ae282f4ed", - "group_id": 22, - "element_type": "text", - "element_params": { - "text": "My new name", - "text_style": "JTUTCJ+ArialMT 8.879999999999995", - "options": null - }, - "inputs": [ - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "New_First_Name", - "placeholder": "", - "instructions": "Type what you want your new first name to be", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "New_Middle_Name", - "placeholder": "", - "instructions": "Type what you want your new middle name to be", - "required": false, - "options": [] - } - }, - { - "input_type": "Tx", - "input_params": { - "text": "", - "text_style": "Helv 10 Tf 0 g", - "output_id": "New_Last_Name", - "placeholder": "", - "instructions": "Type what you want your new last name to be", - "required": false, - "options": [] - } - } - ], - "parent": null - }, - { - "id": "9a3644e2-05f3-4dae-8c64-6abd788d0c67", - "group_id": 24, - "element_type": "text", - "element_params": { - "text": "I also declare: ", - "text_style": "subheading", - "options": null - }, - "inputs": [], - "parent": null - }, - { - "id": "14cdb97d-3024-43f4-932d-6b3f29bf2ffa", - "group_id": 25, - "element_type": "text", - "element_params": { - "text": " I am not now facing criminal charges, nor am I involved in any other court case. ", - "text_style": "indent", - "options": null - }, - "inputs": [], - "parent": null - }, - { - "id": "1a37c28e-c38b-4154-80c9-0ef8238731c6", - "group_id": 26, - "element_type": "text", - "element_params": { - "text": " I have never been convicted of a criminal sex offense (as defined in Alabama Code \u00a7 15-20-21), a crime of moral turpitude, or a felony. ", - "text_style": "indent", - "options": null - }, - "inputs": [], - "parent": null - }, - { - "id": "c38a01c9-d076-4356-b732-276e06311503", - "group_id": 28, - "element_type": "text", - "element_params": { - "text": " I am not asking to change my name to avoid paying my debts or to commit fraud. ", - "text_style": "indent", - "options": null - }, - "inputs": [], - "parent": null - } - ], - "raw_fields": [ - { - "type": "/Tx", - "var_name": "Current_First_Name1", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 143.52, - 660.72, - 315.114, - 674.88 - ], - "field_label": "Current_First_Name1", - "field_instructions": "Type your current first name" - } - }, - { - "type": "/Tx", - "var_name": "Current_Middle_Name1", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 319.867, - 660.368, - 446.006, - 674.629 - ], - "field_label": "Current_Middle_Name1", - "field_instructions": "Type your current middle name" - } - }, - { - "type": "/Tx", - "var_name": "Current_Last_Name1", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 448.846, - 661.013, - 552.413, - 674.629 - ], - "field_label": "Current_Last_Name1", - "field_instructions": "Type your current last name" - } - }, - { - "type": "/Tx", - "var_name": "Current_First_Name2", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 175.92, - 557.04, - 330.412, - 571.2 - ], - "field_label": "Current_First_Name2", - "field_instructions": "Type your current first name" - } - }, - { - "type": "/Tx", - "var_name": "Current_Middle_Name2", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 335.345, - 557.185, - 456.324, - 572.091 - ], - "field_label": "Current_Middle_Name2", - "field_instructions": "Type your current middle name" - } - }, - { - "type": "/Tx", - "var_name": "Current_Last_Name2", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 459.809, - 557.185, - 555.638, - 572.091 - ], - "field_label": "Current_Last_Name2", - "field_instructions": "Type your current last name" - } - }, - { - "type": "/Tx", - "var_name": "Street_Address", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 148.8, - 528.48, - 284.625, - 542.64 - ], - "field_label": "Street_Address", - "field_instructions": "Type your street address" - } - }, - { - "type": "/Tx", - "var_name": "City", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 286.978, - 527.52, - 391.19, - 542.426 - ], - "field_label": "City", - "field_instructions": "Type the name of your city" - } - }, - { - "type": "/Tx", - "var_name": "State", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 392.74, - 528.165, - 462.129, - 542.426 - ], - "field_label": "State", - "field_instructions": "Type the state where you live" - } - }, - { - "type": "/Tx", - "var_name": "Zip", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 464.324, - 527.52, - 554.993, - 543.071 - ], - "field_label": "Zip", - "field_instructions": "Type your zip code" - } - }, - { - "type": "/Tx", - "var_name": "Home_Phone", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 224.4, - 500.16, - 359.16, - 514.32 - ], - "field_label": "Home_Phone", - "field_instructions": "Type your home phone number including area code" - } - }, - { - "type": "/Tx", - "var_name": "Work_Phone", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 392.88, - 500.16, - 555.48, - 514.32 - ], - "field_label": "Work_Phone", - "field_instructions": "Type your work phone number including area code" - } - }, - { - "type": "/Tx", - "var_name": "DOB", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 224.16, - 480.48, - 555.48, - 494.64 - ], - "field_label": "DOB", - "field_instructions": "Type your date of birth as mm/dd/yyyy" - } - }, - { - "type": "/Tx", - "var_name": "Birth_First_Name", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 182.64, - 457.68, - 320.739, - 471.84 - ], - "field_label": "Birth_First_Name", - "field_instructions": "Type the first name you were given at birth" - } - }, - { - "type": "/Tx", - "var_name": "Birth_Middle_Name", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 324.381, - 457.872, - 445.361, - 472.133 - ], - "field_label": "Birth_Middle_Name", - "field_instructions": "Type the middle name you were given at birth" - } - }, - { - "type": "/Tx", - "var_name": "Birth_Last_Name", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 446.911, - 457.872, - 554.993, - 472.133 - ], - "field_label": "Birth_Last_Name", - "field_instructions": "Type the last name you were given at birth" - } - }, - { - "type": "/Tx", - "var_name": "County_Name1", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 221.76, - 685.275, - 413.28, - 700.08 - ], - "field_label": "County_Name1", - "field_instructions": "Type name of Alabama county where Probate Court is located" - } - }, - { - "type": "/Tx", - "var_name": "County_Name2", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 434.16, - 428.64, - 555.48, - 442.8 - ], - "field_label": "County_Name2", - "field_instructions": "Type the name of the county where you live now" - } - }, - { - "type": "/Tx", - "var_name": "DL#", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 410.64, - 406.08, - 555.48, - 420.24 - ], - "field_label": "DL#", - "field_instructions": "Type your driver's license number" - } - }, - { - "type": "/Btn", - "var_name": "PhotoID", - "field_dict": { - "font_info": "/ZaDb 10 Tf 0 g", - "flags": 49152, - "field_type": "button_field", - "field_label": "PhotoID", - "child_fields": [ - { - "coordinates": [ - 320.512, - 405.766, - 330.773, - 416.027 - ] - }, - { - "coordinates": [ - 319.867, - 391.578, - 330.773, - 403.129 - ] - } - ], - "num_children": 2 - } - }, - { - "type": "/Tx", - "var_name": "ID#", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 436.08, - 393.6, - 555.48, - 405.885 - ], - "field_label": "ID#", - "field_instructions": "Type the number from your photo ID (not driver's license)" - } - }, - { - "type": "/Tx", - "var_name": "Why_change_name1", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 466.32, - 375.36, - 555.48, - 389.52 - ], - "field_label": "Why_change_name1", - "field_instructions": "Type why you want to change your name" - } - }, - { - "type": "/Tx", - "var_name": "Why_change_name2", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 77.52, - 360.48, - 555.48, - 374.64 - ], - "field_label": "Why_change_name2", - "field_instructions": "Continue typing why you want to change your name" - } - }, - { - "type": "/Tx", - "var_name": "Why_change_name3", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 77.52, - 346.56, - 555.48, - 359.64 - ], - "field_label": "Why_change_name3", - "field_instructions": "Continue typing why you want to change your name" - } - }, - { - "type": "/Tx", - "var_name": "New_First_Name", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 207.84, - 326.4, - 333.637, - 340.56 - ], - "field_label": "New_First_Name", - "field_instructions": "Type what you want your new first name to be" - } - }, - { - "type": "/Tx", - "var_name": "New_Middle_Name", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 335.989, - 326.313, - 449.876, - 340.575 - ], - "field_label": "New_Middle_Name", - "field_instructions": "Type what you want your new middle name to be" - } - }, - { - "type": "/Tx", - "var_name": "New_Last_Name", - "field_dict": { - "font_info": "/Helv 10 Tf 0 g", - "field_type": "text_field", - "coordinates": [ - 450.781, - 325.668, - 564.021, - 340.575 - ], - "field_label": "New_Last_Name", - "field_instructions": "Type what you want your new last name to be" - } - } - ] -} \ No newline at end of file diff --git a/packages/documents/tsconfig.json b/packages/documents/tsconfig.json deleted file mode 100644 index c4e89861..00000000 --- a/packages/documents/tsconfig.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "./dist", - "emitDeclarationOnly": true - }, - "include": [ - "./src" - ], - "references": [] -} diff --git a/packages/documents/vitest.config.ts b/packages/documents/vitest.config.ts deleted file mode 100644 index dd6c589c..00000000 --- a/packages/documents/vitest.config.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { defineConfig } from 'vitest/config'; - -import sharedTestConfig from '../../vitest.shared'; - -export default defineConfig(sharedTestConfig); diff --git a/packages/form-service/package.json b/packages/form-service/package.json index acaf63a0..813f4701 100644 --- a/packages/form-service/package.json +++ b/packages/form-service/package.json @@ -12,7 +12,6 @@ }, "dependencies": { "@atj/common": "workspace:*", - "@atj/documents": "workspace:*", "@atj/forms": "workspace:*" } } diff --git a/packages/form-service/src/operations/submit-form.ts b/packages/form-service/src/operations/submit-form.ts index 079066b8..00cbbcbe 100644 --- a/packages/form-service/src/operations/submit-form.ts +++ b/packages/form-service/src/operations/submit-form.ts @@ -1,11 +1,12 @@ import { type Result } from '@atj/common'; -import { createFormOutputFieldData, fillPDF } from '@atj/documents'; import { type FormConfig, - sessionIsComplete, - FormDefinition, - FormSession, + type FormDefinition, + type FormSession, applyPromptResponse, + createFormOutputFieldData, + fillPDF, + sessionIsComplete, } from '@atj/forms'; import { getFormFromStorage } from '../context/browser/form-repo'; diff --git a/packages/forms/package.json b/packages/forms/package.json index 67d751b5..eadc666b 100644 --- a/packages/forms/package.json +++ b/packages/forms/package.json @@ -12,6 +12,7 @@ }, "dependencies": { "@atj/common": "workspace:*", + "pdf-lib": "^1.17.1", "zod": "^3.22.4" } } diff --git a/packages/documents/samples/alabama-name-change/ps-12.pdf b/packages/forms/sample-documents/alabama-name-change/ps-12.pdf similarity index 100% rename from packages/documents/samples/alabama-name-change/ps-12.pdf rename to packages/forms/sample-documents/alabama-name-change/ps-12.pdf diff --git a/packages/documents/samples/ca-unlawful-detainer/README.md b/packages/forms/sample-documents/ca-unlawful-detainer/README.md similarity index 100% rename from packages/documents/samples/ca-unlawful-detainer/README.md rename to packages/forms/sample-documents/ca-unlawful-detainer/README.md diff --git a/packages/documents/samples/ca-unlawful-detainer/pos030.pdf b/packages/forms/sample-documents/ca-unlawful-detainer/pos030.pdf similarity index 100% rename from packages/documents/samples/ca-unlawful-detainer/pos030.pdf rename to packages/forms/sample-documents/ca-unlawful-detainer/pos030.pdf diff --git a/packages/documents/samples/ca-unlawful-detainer/ud-105.fields.json b/packages/forms/sample-documents/ca-unlawful-detainer/ud-105.fields.json similarity index 100% rename from packages/documents/samples/ca-unlawful-detainer/ud-105.fields.json rename to packages/forms/sample-documents/ca-unlawful-detainer/ud-105.fields.json diff --git a/packages/documents/samples/ca-unlawful-detainer/ud105.pdf b/packages/forms/sample-documents/ca-unlawful-detainer/ud105.pdf similarity index 100% rename from packages/documents/samples/ca-unlawful-detainer/ud105.pdf rename to packages/forms/sample-documents/ca-unlawful-detainer/ud105.pdf diff --git a/packages/documents/samples/dod_character.pdf b/packages/forms/sample-documents/dod_character.pdf similarity index 100% rename from packages/documents/samples/dod_character.pdf rename to packages/forms/sample-documents/dod_character.pdf diff --git a/packages/documents/samples/doj-pardon-marijuana/README.md b/packages/forms/sample-documents/doj-pardon-marijuana/README.md similarity index 100% rename from packages/documents/samples/doj-pardon-marijuana/README.md rename to packages/forms/sample-documents/doj-pardon-marijuana/README.md diff --git a/packages/documents/samples/doj-pardon-marijuana/application_for_certificate_of_pardon_for_simple_marijuana_possession.pdf b/packages/forms/sample-documents/doj-pardon-marijuana/application_for_certificate_of_pardon_for_simple_marijuana_possession.pdf similarity index 100% rename from packages/documents/samples/doj-pardon-marijuana/application_for_certificate_of_pardon_for_simple_marijuana_possession.pdf rename to packages/forms/sample-documents/doj-pardon-marijuana/application_for_certificate_of_pardon_for_simple_marijuana_possession.pdf diff --git a/packages/documents/src/__tests__/doj-pardon-marijuana.test.ts b/packages/forms/src/documents/__tests__/doj-pardon-marijuana.test.ts similarity index 95% rename from packages/documents/src/__tests__/doj-pardon-marijuana.test.ts rename to packages/forms/src/documents/__tests__/doj-pardon-marijuana.test.ts index 7b5d4a1d..4e9a750d 100644 --- a/packages/documents/src/__tests__/doj-pardon-marijuana.test.ts +++ b/packages/forms/src/documents/__tests__/doj-pardon-marijuana.test.ts @@ -1,9 +1,11 @@ import { describe, expect, it } from 'vitest'; +import { Success } from '@atj/common'; + import { loadSamplePDF } from './sample-data'; import { fillPDF, getDocumentFieldData } from '../pdf'; -import { Success } from '@atj/common'; -import { DocumentFieldMap, FormBuilder } from '@atj/forms'; +import { FormBuilder } from '../..'; +import { DocumentFieldMap } from '..'; describe('DOJ Pardon Office marijuana pardon application form', () => { it('produces valid PDF from imported PDF', async () => { diff --git a/packages/documents/src/__tests__/dummy.test.ts b/packages/forms/src/documents/__tests__/dummy.test.ts similarity index 100% rename from packages/documents/src/__tests__/dummy.test.ts rename to packages/forms/src/documents/__tests__/dummy.test.ts diff --git a/packages/documents/src/__tests__/extract.test.ts b/packages/forms/src/documents/__tests__/extract.test.ts similarity index 100% rename from packages/documents/src/__tests__/extract.test.ts rename to packages/forms/src/documents/__tests__/extract.test.ts diff --git a/packages/documents/src/__tests__/fill-pdf.test.ts b/packages/forms/src/documents/__tests__/fill-pdf.test.ts similarity index 99% rename from packages/documents/src/__tests__/fill-pdf.test.ts rename to packages/forms/src/documents/__tests__/fill-pdf.test.ts index 078e7bc1..51ffb4da 100644 --- a/packages/documents/src/__tests__/fill-pdf.test.ts +++ b/packages/forms/src/documents/__tests__/fill-pdf.test.ts @@ -1,8 +1,9 @@ import { beforeAll, describe, expect, it } from 'vitest'; +import { type Failure, type Success } from '@atj/common'; + import { getDocumentFieldData, fillPDF } from '..'; import { loadSamplePDF } from './sample-data'; -import { type Failure, type Success } from '@atj/common'; describe('PDF form filler', () => { let pdfBytes: Uint8Array; diff --git a/packages/documents/src/__tests__/sample-data.ts b/packages/forms/src/documents/__tests__/sample-data.ts similarity index 85% rename from packages/documents/src/__tests__/sample-data.ts rename to packages/forms/src/documents/__tests__/sample-data.ts index 7fe0f441..e122d9d8 100644 --- a/packages/documents/src/__tests__/sample-data.ts +++ b/packages/forms/src/documents/__tests__/sample-data.ts @@ -1,7 +1,7 @@ import path from 'path'; import { promises as fs } from 'fs'; -const samplesDirectory = path.resolve(__dirname, '../../samples'); +const samplesDirectory = path.resolve(__dirname, '../../../sample-documents'); export const loadSamplePDF = async (fileName: `${string}.pdf`) => { const samplePdfPath = path.join(samplesDirectory, fileName); diff --git a/packages/documents/src/__tests__/suggestions.test.ts b/packages/forms/src/documents/__tests__/suggestions.test.ts similarity index 100% rename from packages/documents/src/__tests__/suggestions.test.ts rename to packages/forms/src/documents/__tests__/suggestions.test.ts diff --git a/packages/documents/src/document.ts b/packages/forms/src/documents/document.ts similarity index 96% rename from packages/documents/src/document.ts rename to packages/forms/src/documents/document.ts index 16640b95..872dcd9a 100644 --- a/packages/documents/src/document.ts +++ b/packages/forms/src/documents/document.ts @@ -1,16 +1,15 @@ import { - DocumentFieldMap, FormDefinition, FormElement, addFormOutput, addFormElements, addFormElementMap, updateFormSummary, -} from '@atj/forms'; +} from '..'; +import { InputElement } from '../config/elements/input'; import { PDFDocument, getDocumentFieldData } from './pdf'; import { getSuggestedFormElementsFromCache } from './suggestions'; -import { InputElement } from '@atj/forms/src/config/elements/input'; -import { stringToBase64 } from './util'; +import { DocumentFieldMap } from './types'; export type DocumentTemplate = PDFDocument; diff --git a/packages/forms/src/documents/index.ts b/packages/forms/src/documents/index.ts index 658aa192..1ad9ff63 100644 --- a/packages/forms/src/documents/index.ts +++ b/packages/forms/src/documents/index.ts @@ -1,53 +1,19 @@ -export type DocumentFieldValue = - | { - type: 'TextField'; - name: string; - label: string; - value: string; - maxLength?: number; - required: boolean; - } - | { - type: 'CheckBox'; - name: string; - label: string; - value: boolean; - required: boolean; - } - | { - type: 'Dropdown'; - name: string; - label: string; - value: string[]; - required: boolean; - } - | { - type: 'OptionList'; - name: string; - label: string; - value: string[]; - required: boolean; - } - | { - type: 'RadioGroup'; - name: string; - options: string[]; - label: string; - value: string; - required: boolean; - } - | { - type: 'Paragraph'; - name: string; - options: string[]; - label: string; - value: string; - required: boolean; - } - | { - type: 'not-supported'; - name: string; - error: string; - }; +export * from './document'; +export * from './pdf'; +export * from './suggestions'; +export * from './types'; -export type DocumentFieldMap = Record; +export const SAMPLE_DOCUMENTS = [ + { + path: 'sample-documents/ca-unlawful-detainer/ud105.pdf', + title: 'California UD-105 (unlawful detainer)', + }, + { + path: 'sample-documents/alabama-name-change/ps-12.pdf', + title: 'Alabama PS-12 (name change)', + }, + { + path: 'sample-documents/doj-pardon-marijuana/application_for_certificate_of_pardon_for_simple_marijuana_possession.pdf', + title: 'DOJ Marijuana Pardon Application', + }, +]; diff --git a/packages/forms/src/documents/pdf/al_name_change.ts b/packages/forms/src/documents/pdf/al_name_change.ts new file mode 100644 index 00000000..d243c2b3 --- /dev/null +++ b/packages/forms/src/documents/pdf/al_name_change.ts @@ -0,0 +1,869 @@ +export default { + raw_text: 'Request to Change Name', + title: 'Request to Change Name (For An Adult)', + description: '', + elements: [ + { + id: '1fc0b74a-7139-46a7-9aad-8e3e3ff94a6d', + group_id: 2, + element_type: 'text', + element_params: { + text: 'In the Probate Court of (county): ', + text_style: 'JTUTCJ+ArialMT 9.840000000000032', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'County_Name1', + placeholder: '', + instructions: 'Type name of Alabama county where you live', + required: false, + options: [], + }, + }, + ], + parent: null, + }, + { + id: '6904a3ef-17f6-4a1b-83c7-4a963f1a43c5', + group_id: 3, + element_type: 'text', + element_params: { + text: 'Your current name', + text_style: 'JTUTCJ+ArialMT 9.840000000000032', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Current_First_Name1', + placeholder: '', + instructions: 'Type your current first name', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Current_Middle_Name1', + placeholder: '', + instructions: 'Type your current middle name', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Current_Last_Name1', + placeholder: '', + instructions: 'Type your current last name', + required: false, + options: [], + }, + }, + ], + parent: null, + }, + { + id: '0a10d256-c938-4c83-9045-8f31df99bbff', + group_id: 5, + element_type: 'text', + element_params: { + text: 'To ask the court to change your name, you must fill out this form, and: ', + text_style: 'subheading', + options: null, + }, + inputs: [], + parent: null, + }, + { + id: '9ffecb48-b274-44a9-ab21-17f90db129ca', + group_id: 6, + element_type: 'text', + element_params: { + text: 'Attach a certified copy of your birth certificate and a copy of your photo ID, and ', + text_style: 'indent', + options: null, + }, + inputs: [], + parent: null, + }, + { + id: '21ce04d1-7d40-40c9-bdd5-e738b801a6d3', + group_id: 7, + element_type: 'text', + element_params: { + text: ' File your form and attachments in the same county where you live. ', + text_style: 'indent', + options: null, + }, + inputs: [], + parent: null, + }, + { + id: 'fd565668-436f-42f3-9969-4de1b86db4ae', + group_id: 8, + element_type: 'text', + element_params: { + text: 'I declare that the following information is true: ', + text_style: 'subheading', + options: null, + }, + inputs: [], + parent: null, + }, + { + id: '767b5b4e-f1f0-4ca2-a606-d74562d4b78b', + group_id: 9, + element_type: 'text', + element_params: { + text: 'My current name', + text_style: 'JTUTCJ+ArialMT 8.879999999999995', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Current_First_Name2', + placeholder: '', + instructions: 'Type your current first name', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Current_Middle_Name2', + placeholder: '', + instructions: 'Type your current middle name', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Current_Last_Name2', + placeholder: '', + instructions: 'Type your current last name', + required: false, + options: [], + }, + }, + ], + parent: null, + }, + { + id: '91955d9c-b3fc-4190-b1fd-bfddd49a2a6c', + group_id: 11, + element_type: 'text', + element_params: { + text: 'My address', + text_style: 'JTUTCJ+ArialMT 8.879999999999995', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Street_Address', + placeholder: '', + instructions: 'Type your street address', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'City', + placeholder: '', + instructions: 'Type the name of your city', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'State', + placeholder: '', + instructions: 'Type the state where you live', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Zip', + placeholder: '', + instructions: 'Type your zip code', + required: false, + options: [], + }, + }, + ], + parent: null, + }, + { + id: '7ce2801f-022d-4140-b004-fdcdaf9a0767', + group_id: 13, + element_type: 'text', + element_params: { + text: 'My phone numbers', + text_style: 'DURMBL+Arial-BoldMT 8.879999999999995', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Home_Phone', + placeholder: '', + instructions: 'Type your home phone number including area code', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Work_Phone', + placeholder: '', + instructions: 'Type your work phone number including area code', + required: false, + options: [], + }, + }, + ], + parent: null, + }, + { + id: 'c3212cab-6019-4e60-8198-f11b87c81e82', + group_id: 14, + element_type: 'text', + element_params: { + text: 'My date of birth is (mm/dd/yyyy): ', + text_style: 'JTUTCJ+ArialMT 8.879999999999995', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'DOB', + placeholder: '', + instructions: 'Type your date of birth as mm/dd/yyyy', + required: false, + options: [], + }, + }, + ], + parent: null, + }, + { + id: 'ce713b94-0008-43ab-ace4-6b38d01b2f76', + group_id: 15, + element_type: 'text', + element_params: { + text: 'My name at birth', + text_style: 'JTUTCJ+ArialMT 8.879999999999995', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Birth_First_Name', + placeholder: '', + instructions: 'Type the first name you were given at birth', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Birth_Middle_Name', + placeholder: '', + instructions: 'Type the middle name you were given at birth', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Birth_Last_Name', + placeholder: '', + instructions: 'Type the last name you were given at birth', + required: false, + options: [], + }, + }, + ], + parent: null, + }, + { + id: 'f228e971-d4db-43f6-a03b-4eb009f214b0', + group_id: 17, + element_type: 'text', + element_params: { + text: 'I am an adult (19 or older), of sound mind, and live in (name of Alabama county): ', + text_style: 'LEDWHU+TimesNewRomanPSMT 8.879999999999995', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'County_Name2', + placeholder: '', + instructions: 'Type the name of the county where you live now', + required: false, + options: [], + }, + }, + ], + parent: null, + }, + { + id: 'dcb5d901-a293-4f53-b663-a4d401af0812', + group_id: 18, + element_type: 'text', + element_params: { + text: 'The attached copy of my photo ID is my (choose one):', + text_style: 'heading', + options: null, + }, + inputs: [], + parent: 'PhotoID', + }, + { + id: 'dcb5d901-a293-4f53-b663-a4d401ac0812', + group_id: 18, + element_type: 'text', + element_params: { + text: 'Driver\u2019s license, # ', + text_style: 'JTUTCJ+ArialMT 12.0', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'DL#', + placeholder: '', + instructions: "Type your driver's license number", + required: false, + options: [], + }, + }, + ], + parent: 'PhotoID', + }, + { + id: '1a8cbd28-f600-47f8-9ce0-85ae136ba338', + group_id: 18, + element_type: 'text', + element_params: { + text: 'Non-driver\u2019s photo, ID #: ', + text_style: 'JTUTCJ+ArialMT 8.879999999999995', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'ID#', + placeholder: '', + instructions: + "Type the number from your photo ID (not driver's license)", + required: false, + options: [], + }, + }, + ], + parent: 'PhotoID', + }, + { + id: 'a532ebcf-b71a-4135-9de1-819bc98815b0', + group_id: 19, + element_type: 'text', + element_params: { + text: 'I ask the court to change my name because (explain why you want to change your name): ', + text_style: 'LEDWHU+TimesNewRomanPSMT 8.879999999999995', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'Why_change_name1', + placeholder: '', + instructions: 'Type why you want to change your name', + required: false, + options: [], + }, + }, + ], + parent: null, + }, + { + id: 'f21048d9-95f4-4e83-843b-cf8ae282f4ed', + group_id: 22, + element_type: 'text', + element_params: { + text: 'My new name', + text_style: 'JTUTCJ+ArialMT 8.879999999999995', + options: null, + }, + inputs: [ + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'New_First_Name', + placeholder: '', + instructions: 'Type what you want your new first name to be', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'New_Middle_Name', + placeholder: '', + instructions: 'Type what you want your new middle name to be', + required: false, + options: [], + }, + }, + { + input_type: 'Tx', + input_params: { + text: "", + text_style: 'Helv 10 Tf 0 g', + output_id: 'New_Last_Name', + placeholder: '', + instructions: 'Type what you want your new last name to be', + required: false, + options: [], + }, + }, + ], + parent: null, + }, + { + id: '9a3644e2-05f3-4dae-8c64-6abd788d0c67', + group_id: 24, + element_type: 'text', + element_params: { + text: 'I also declare: ', + text_style: 'subheading', + options: null, + }, + inputs: [], + parent: null, + }, + { + id: '14cdb97d-3024-43f4-932d-6b3f29bf2ffa', + group_id: 25, + element_type: 'text', + element_params: { + text: ' I am not now facing criminal charges, nor am I involved in any other court case. ', + text_style: 'indent', + options: null, + }, + inputs: [], + parent: null, + }, + { + id: '1a37c28e-c38b-4154-80c9-0ef8238731c6', + group_id: 26, + element_type: 'text', + element_params: { + text: ' I have never been convicted of a criminal sex offense (as defined in Alabama Code \u00a7 15-20-21), a crime of moral turpitude, or a felony. ', + text_style: 'indent', + options: null, + }, + inputs: [], + parent: null, + }, + { + id: 'c38a01c9-d076-4356-b732-276e06311503', + group_id: 28, + element_type: 'text', + element_params: { + text: ' I am not asking to change my name to avoid paying my debts or to commit fraud. ', + text_style: 'indent', + options: null, + }, + inputs: [], + parent: null, + }, + ], + raw_fields: [ + { + type: '/Tx', + var_name: 'Current_First_Name1', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [143.52, 660.72, 315.114, 674.88], + field_label: 'Current_First_Name1', + field_instructions: 'Type your current first name', + }, + }, + { + type: '/Tx', + var_name: 'Current_Middle_Name1', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [319.867, 660.368, 446.006, 674.629], + field_label: 'Current_Middle_Name1', + field_instructions: 'Type your current middle name', + }, + }, + { + type: '/Tx', + var_name: 'Current_Last_Name1', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [448.846, 661.013, 552.413, 674.629], + field_label: 'Current_Last_Name1', + field_instructions: 'Type your current last name', + }, + }, + { + type: '/Tx', + var_name: 'Current_First_Name2', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [175.92, 557.04, 330.412, 571.2], + field_label: 'Current_First_Name2', + field_instructions: 'Type your current first name', + }, + }, + { + type: '/Tx', + var_name: 'Current_Middle_Name2', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [335.345, 557.185, 456.324, 572.091], + field_label: 'Current_Middle_Name2', + field_instructions: 'Type your current middle name', + }, + }, + { + type: '/Tx', + var_name: 'Current_Last_Name2', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [459.809, 557.185, 555.638, 572.091], + field_label: 'Current_Last_Name2', + field_instructions: 'Type your current last name', + }, + }, + { + type: '/Tx', + var_name: 'Street_Address', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [148.8, 528.48, 284.625, 542.64], + field_label: 'Street_Address', + field_instructions: 'Type your street address', + }, + }, + { + type: '/Tx', + var_name: 'City', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [286.978, 527.52, 391.19, 542.426], + field_label: 'City', + field_instructions: 'Type the name of your city', + }, + }, + { + type: '/Tx', + var_name: 'State', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [392.74, 528.165, 462.129, 542.426], + field_label: 'State', + field_instructions: 'Type the state where you live', + }, + }, + { + type: '/Tx', + var_name: 'Zip', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [464.324, 527.52, 554.993, 543.071], + field_label: 'Zip', + field_instructions: 'Type your zip code', + }, + }, + { + type: '/Tx', + var_name: 'Home_Phone', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [224.4, 500.16, 359.16, 514.32], + field_label: 'Home_Phone', + field_instructions: 'Type your home phone number including area code', + }, + }, + { + type: '/Tx', + var_name: 'Work_Phone', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [392.88, 500.16, 555.48, 514.32], + field_label: 'Work_Phone', + field_instructions: 'Type your work phone number including area code', + }, + }, + { + type: '/Tx', + var_name: 'DOB', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [224.16, 480.48, 555.48, 494.64], + field_label: 'DOB', + field_instructions: 'Type your date of birth as mm/dd/yyyy', + }, + }, + { + type: '/Tx', + var_name: 'Birth_First_Name', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [182.64, 457.68, 320.739, 471.84], + field_label: 'Birth_First_Name', + field_instructions: 'Type the first name you were given at birth', + }, + }, + { + type: '/Tx', + var_name: 'Birth_Middle_Name', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [324.381, 457.872, 445.361, 472.133], + field_label: 'Birth_Middle_Name', + field_instructions: 'Type the middle name you were given at birth', + }, + }, + { + type: '/Tx', + var_name: 'Birth_Last_Name', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [446.911, 457.872, 554.993, 472.133], + field_label: 'Birth_Last_Name', + field_instructions: 'Type the last name you were given at birth', + }, + }, + { + type: '/Tx', + var_name: 'County_Name1', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [221.76, 685.275, 413.28, 700.08], + field_label: 'County_Name1', + field_instructions: + 'Type name of Alabama county where Probate Court is located', + }, + }, + { + type: '/Tx', + var_name: 'County_Name2', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [434.16, 428.64, 555.48, 442.8], + field_label: 'County_Name2', + field_instructions: 'Type the name of the county where you live now', + }, + }, + { + type: '/Tx', + var_name: 'DL#', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [410.64, 406.08, 555.48, 420.24], + field_label: 'DL#', + field_instructions: "Type your driver's license number", + }, + }, + { + type: '/Btn', + var_name: 'PhotoID', + field_dict: { + font_info: '/ZaDb 10 Tf 0 g', + flags: 49152, + field_type: 'button_field', + field_label: 'PhotoID', + child_fields: [ + { + coordinates: [320.512, 405.766, 330.773, 416.027], + }, + { + coordinates: [319.867, 391.578, 330.773, 403.129], + }, + ], + num_children: 2, + }, + }, + { + type: '/Tx', + var_name: 'ID#', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [436.08, 393.6, 555.48, 405.885], + field_label: 'ID#', + field_instructions: + "Type the number from your photo ID (not driver's license)", + }, + }, + { + type: '/Tx', + var_name: 'Why_change_name1', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [466.32, 375.36, 555.48, 389.52], + field_label: 'Why_change_name1', + field_instructions: 'Type why you want to change your name', + }, + }, + { + type: '/Tx', + var_name: 'Why_change_name2', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [77.52, 360.48, 555.48, 374.64], + field_label: 'Why_change_name2', + field_instructions: 'Continue typing why you want to change your name', + }, + }, + { + type: '/Tx', + var_name: 'Why_change_name3', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [77.52, 346.56, 555.48, 359.64], + field_label: 'Why_change_name3', + field_instructions: 'Continue typing why you want to change your name', + }, + }, + { + type: '/Tx', + var_name: 'New_First_Name', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [207.84, 326.4, 333.637, 340.56], + field_label: 'New_First_Name', + field_instructions: 'Type what you want your new first name to be', + }, + }, + { + type: '/Tx', + var_name: 'New_Middle_Name', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [335.989, 326.313, 449.876, 340.575], + field_label: 'New_Middle_Name', + field_instructions: 'Type what you want your new middle name to be', + }, + }, + { + type: '/Tx', + var_name: 'New_Last_Name', + field_dict: { + font_info: '/Helv 10 Tf 0 g', + field_type: 'text_field', + coordinates: [450.781, 325.668, 564.021, 340.575], + field_label: 'New_Last_Name', + field_instructions: 'Type what you want your new last name to be', + }, + }, + ], +}; diff --git a/packages/documents/src/pdf/extract.ts b/packages/forms/src/documents/pdf/extract.ts similarity index 96% rename from packages/documents/src/pdf/extract.ts rename to packages/forms/src/documents/pdf/extract.ts index 01e38da8..76295b8f 100644 --- a/packages/documents/src/pdf/extract.ts +++ b/packages/forms/src/documents/pdf/extract.ts @@ -1,7 +1,7 @@ import * as pdfLib from 'pdf-lib'; -import { type DocumentFieldMap, type DocumentFieldValue } from '@atj/forms'; import { stringToBase64 } from '../util'; +import type { DocumentFieldValue, DocumentFieldMap } from '../types'; export const getDocumentFieldData = async ( pdfBytes: Uint8Array diff --git a/packages/documents/src/pdf/generate-dummy.ts b/packages/forms/src/documents/pdf/generate-dummy.ts similarity index 100% rename from packages/documents/src/pdf/generate-dummy.ts rename to packages/forms/src/documents/pdf/generate-dummy.ts diff --git a/packages/documents/src/pdf/generate.ts b/packages/forms/src/documents/pdf/generate.ts similarity index 96% rename from packages/documents/src/pdf/generate.ts rename to packages/forms/src/documents/pdf/generate.ts index 298982bc..b2380ae2 100644 --- a/packages/documents/src/pdf/generate.ts +++ b/packages/forms/src/documents/pdf/generate.ts @@ -1,8 +1,8 @@ import { PDFDocument, type PDFForm } from 'pdf-lib'; import { Result } from '@atj/common'; -import { FormOutput } from '@atj/forms'; -import { PDFFieldType } from '.'; +import { type FormOutput } from '../..'; +import { type PDFFieldType } from '.'; export const createFormOutputFieldData = ( output: FormOutput, diff --git a/packages/documents/src/pdf/index.ts b/packages/forms/src/documents/pdf/index.ts similarity index 100% rename from packages/documents/src/pdf/index.ts rename to packages/forms/src/documents/pdf/index.ts diff --git a/packages/documents/src/pdf/mock-api.ts b/packages/forms/src/documents/pdf/mock-api.ts similarity index 96% rename from packages/documents/src/pdf/mock-api.ts rename to packages/forms/src/documents/pdf/mock-api.ts index b8cf45a2..dddbd6c6 100644 --- a/packages/documents/src/pdf/mock-api.ts +++ b/packages/forms/src/documents/pdf/mock-api.ts @@ -1,17 +1,19 @@ import * as z from 'zod'; import { - type DocumentFieldMap, type FormElement, type FormElementId, type FormElementMap, -} from '@atj/forms'; -import { type InputElement } from '@atj/forms/src/config/elements/input'; +} from '../..'; + +import { ParagraphElement } from '../../config/elements/paragraph'; +import { InputElement } from '../../config/elements/input'; +import { FieldsetElement } from '../../config/elements/fieldset'; -import json from './al_name_change.json' assert { type: 'json' }; -import { FieldsetElement } from '@atj/forms/src/config/elements/fieldset'; -import { ParagraphElement } from '@atj/forms/src/config/elements/paragraph'; import { stringToBase64 } from '../util'; +import { DocumentFieldMap } from '../types'; + +import json from './al_name_change'; const TxInput = z.object({ input_type: z.literal('Tx'), diff --git a/packages/documents/src/suggestions.ts b/packages/forms/src/documents/suggestions.ts similarity index 100% rename from packages/documents/src/suggestions.ts rename to packages/forms/src/documents/suggestions.ts diff --git a/packages/forms/src/documents/types.ts b/packages/forms/src/documents/types.ts new file mode 100644 index 00000000..658aa192 --- /dev/null +++ b/packages/forms/src/documents/types.ts @@ -0,0 +1,53 @@ +export type DocumentFieldValue = + | { + type: 'TextField'; + name: string; + label: string; + value: string; + maxLength?: number; + required: boolean; + } + | { + type: 'CheckBox'; + name: string; + label: string; + value: boolean; + required: boolean; + } + | { + type: 'Dropdown'; + name: string; + label: string; + value: string[]; + required: boolean; + } + | { + type: 'OptionList'; + name: string; + label: string; + value: string[]; + required: boolean; + } + | { + type: 'RadioGroup'; + name: string; + options: string[]; + label: string; + value: string; + required: boolean; + } + | { + type: 'Paragraph'; + name: string; + options: string[]; + label: string; + value: string; + required: boolean; + } + | { + type: 'not-supported'; + name: string; + error: string; + }; + +export type DocumentFieldMap = Record; diff --git a/packages/documents/src/util.ts b/packages/forms/src/documents/util.ts similarity index 100% rename from packages/documents/src/util.ts rename to packages/forms/src/documents/util.ts diff --git a/packages/forms/src/index.ts b/packages/forms/src/index.ts index 32fdbedb..6df46d1f 100644 --- a/packages/forms/src/index.ts +++ b/packages/forms/src/index.ts @@ -1,6 +1,6 @@ import { FormConfig } from './config'; import { SequenceElement } from './config/elements/sequence'; -import { type DocumentFieldMap } from './documents'; +import { DocumentFieldMap } from './documents'; import { type FormElement, type FormElementId, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 23ef4f2b..c216b7b7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -81,9 +81,6 @@ importers: '@atj/design': specifier: workspace:* version: link:../../packages/design - '@atj/documents': - specifier: workspace:* - version: link:../../packages/documents '@atj/form-service': specifier: workspace:* version: link:../../packages/form-service @@ -131,9 +128,6 @@ importers: '@atj/design': specifier: workspace:* version: link:../../packages/design - '@atj/documents': - specifier: workspace:* - version: link:../../packages/documents '@atj/form-service': specifier: workspace:* version: link:../../packages/form-service @@ -189,7 +183,7 @@ importers: version: 29.7.0(@types/node@20.8.7)(ts-node@10.9.2) ts-jest: specifier: ^29.1.1 - version: 29.1.1(@babel/core@7.23.7)(esbuild@0.19.12)(jest@29.7.0)(typescript@5.3.3) + version: 29.1.1(@babel/core@7.23.0)(esbuild@0.19.12)(jest@29.7.0)(typescript@5.3.3) packages/common: {} @@ -214,9 +208,6 @@ importers: '@atj/common': specifier: workspace:* version: link:../common - '@atj/documents': - specifier: workspace:* - version: link:../documents '@atj/form-service': specifier: workspace:* version: link:../form-service @@ -365,9 +356,9 @@ importers: packages/docassemble: dependencies: - '@atj/documents': + '@atj/forms': specifier: workspace:* - version: link:../documents + version: link:../forms devDependencies: '@vitest/coverage-v8': specifier: ^0.34.6 @@ -376,33 +367,11 @@ importers: specifier: ^0.34.6 version: 0.34.6(@vitest/ui@1.2.2) - packages/documents: - dependencies: - '@atj/common': - specifier: workspace:* - version: link:../common - '@atj/forms': - specifier: workspace:* - version: link:../forms - pdf-lib: - specifier: ^1.17.1 - version: 1.17.1 - zod: - specifier: ^3.22.4 - version: 3.22.4 - devDependencies: - '@types/node': - specifier: ^20.10.4 - version: 20.10.4 - packages/form-service: dependencies: '@atj/common': specifier: workspace:* version: link:../common - '@atj/documents': - specifier: workspace:* - version: link:../documents '@atj/forms': specifier: workspace:* version: link:../forms @@ -412,6 +381,9 @@ importers: '@atj/common': specifier: workspace:* version: link:../common + pdf-lib: + specifier: ^1.17.1 + version: 1.17.1 zod: specifier: ^3.22.4 version: 3.22.4 @@ -6140,12 +6112,6 @@ packages: undici-types: 5.26.5 dev: false - /@types/node@20.10.4: - resolution: {integrity: sha512-D08YG6rr8X90YB56tSIuBaddy/UXAA9RKJoFvrsnogAum/0pmjkgi4+2nx96A330FmioegBWmEYQ+syqCFaveg==} - dependencies: - undici-types: 5.26.5 - dev: true - /@types/node@20.11.16: resolution: {integrity: sha512-gKb0enTmRCzXSSUJDq6/sPcqrfCv2mkkG6Jt/clpn5eiCbKTY+SgZUxo+p8ZKMof5dCp9vHQUAB7wOUTod22wQ==} dependencies: @@ -9580,7 +9546,7 @@ packages: dependencies: semver: 7.6.0 shelljs: 0.8.5 - typescript: 5.5.0-dev.20240313 + typescript: 5.5.0-dev.20240321 dev: false /dset@3.1.3: @@ -18040,7 +18006,7 @@ packages: resolution: {integrity: sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==} dev: true - /ts-jest@29.1.1(@babel/core@7.23.7)(esbuild@0.19.12)(jest@29.7.0)(typescript@5.3.3): + /ts-jest@29.1.1(@babel/core@7.23.0)(esbuild@0.19.12)(jest@29.7.0)(typescript@5.3.3): resolution: {integrity: sha512-D6xjnnbP17cC85nliwGiL+tpoKN0StpgE0TeOjXQTU6MVCfsB4v7aW05CgQ/1OywGb0x/oy9hHFnN+sczTiRaA==} engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} hasBin: true @@ -18061,7 +18027,7 @@ packages: esbuild: optional: true dependencies: - '@babel/core': 7.23.7 + '@babel/core': 7.23.0 bs-logger: 0.2.6 esbuild: 0.19.12 fast-json-stable-stringify: 2.1.0 @@ -18372,8 +18338,8 @@ packages: engines: {node: '>=14.17'} hasBin: true - /typescript@5.5.0-dev.20240313: - resolution: {integrity: sha512-6fXTCRKCmprlwHuUHH92w6Ll7na8PtjPCCUmUTHa2yl2lJZBtWNw4P/JmV0PuNMaByRWVX6ai008B7TYBKp3QA==} + /typescript@5.5.0-dev.20240321: + resolution: {integrity: sha512-QEUqMB18VAUQBHtHlq8BfjxGZzFkavH5fhZn+I97N67mDZTa86n1S8kiRKmrbxVwPAdvn3DYtJzcGq5OvdWkmQ==} engines: {node: '>=14.17'} hasBin: true dev: false diff --git a/tsconfig.json b/tsconfig.json index 4810dcc6..69631b20 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,13 +13,6 @@ "target": "ESNext", "resolveJsonModule": true, }, - "files": [ - // temporary for mock-api - "./packages/documents/src/pdf/al_name_change.json" - ], - "include": [ - "./packages/*/src/**/*.json", - ], "exclude": [ "node_modules", "**/*/lib", @@ -32,9 +25,6 @@ { "path": "./packages/design/tsconfig.json" }, - { - "path": "./packages/documents/tsconfig.json" - }, { "path": "./packages/form-service/tsconfig.json" }, From 14e05193ac587dc34342290d93e28f17af6bad5d Mon Sep 17 00:00:00 2001 From: Daniel Naab Date: Thu, 21 Mar 2024 13:50:27 -0500 Subject: [PATCH 3/5] Add setFormSummary() and addDocument() to FormBuilder; wire up to FormManager. --- .../FormList/PDFFileSelect/hooks.ts | 86 ++++++------------- packages/forms/src/builder/index.ts | 23 ++++- .../__tests__/doj-pardon-marijuana.test.ts | 2 - packages/forms/src/documents/document.ts | 1 - 4 files changed, 43 insertions(+), 69 deletions(-) diff --git a/packages/design/src/FormManager/FormList/PDFFileSelect/hooks.ts b/packages/design/src/FormManager/FormList/PDFFileSelect/hooks.ts index 6ffed12c..017546bb 100644 --- a/packages/design/src/FormManager/FormList/PDFFileSelect/hooks.ts +++ b/packages/design/src/FormManager/FormList/PDFFileSelect/hooks.ts @@ -1,12 +1,6 @@ import { useNavigate } from 'react-router-dom'; -import { type Result } from '@atj/common'; -import { - type FormElement, - type FormSummary, - addDocument, - createForm, -} from '@atj/forms'; +import { FormBuilder } from '@atj/forms'; import { type FormService } from '@atj/form-service'; export const useDocumentImporter = ( @@ -18,10 +12,19 @@ export const useDocumentImporter = ( return { actions: { stepOneSelectPdfByUrl: async (url: string) => { - const result = await stepOneSelectPdfByUrl( - { formService, baseUrl }, - url - ); + const data = await fetchUint8Array(`${baseUrl}${url}`); + + const builder = new FormBuilder(); + builder.setFormSummary({ + title: url, + description: '', + }); + await builder.addDocument({ + name: url, + data, + }); + + const result = formService.addForm(builder.form); if (result.success) { navigate(`/${result.data}/edit`); } @@ -30,10 +33,13 @@ export const useDocumentImporter = ( name: string; data: Uint8Array; }) => { - const result = await stepOneSelectPdfByUpload( - { formService }, - fileDetails - ); + const builder = new FormBuilder(); + builder.setFormSummary({ + title: fileDetails.name, + description: '', + }); + await builder.addDocument(fileDetails); + const result = await formService.addForm(builder.form); if (result.success) { navigate(`/${result.data}/edit`); } @@ -42,52 +48,8 @@ export const useDocumentImporter = ( }; }; -export const stepOneSelectPdfByUrl = async ( - ctx: { formService: FormService; baseUrl: string }, - url: string -): Promise> => { - const completeUrl = `${ctx.baseUrl}${url}`; - const response = await fetch(completeUrl); +const fetchUint8Array = async (url: string) => { + const response = await fetch(url); const blob = await response.blob(); - const data = new Uint8Array(await blob.arrayBuffer()); - - const emptyForm = createForm({ - title: url, - description: '', - }); - const { updatedForm } = await addDocument(emptyForm, { - name: url, - data, - }); - return ctx.formService.addForm(updatedForm); -}; - -export const stepOneSelectPdfByUpload = async ( - ctx: { formService: FormService }, - fileDetails: { - name: string; - data: Uint8Array; - } -): Promise> => { - const emptyForm = createForm( - { - title: fileDetails.name, - description: '', - }, - { - root: 'root', - elements: [ - { - type: 'form-summary', - id: 'form-summary', - data: { - title: fileDetails.name, - description: '', - }, - } as FormElement, - ], - } - ); - const { updatedForm } = await addDocument(emptyForm, fileDetails); - return ctx.formService.addForm(updatedForm); + return new Uint8Array(await blob.arrayBuffer()); }; diff --git a/packages/forms/src/builder/index.ts b/packages/forms/src/builder/index.ts index e2cdbdbe..1fc024e3 100644 --- a/packages/forms/src/builder/index.ts +++ b/packages/forms/src/builder/index.ts @@ -1,13 +1,28 @@ -import { nullFormDefinition, type FormDefinition } from '..'; +import { + type FormDefinition, + type FormSummary, + addDocument, + nullFormDefinition, + updateFormSummary, +} from '..'; export class FormBuilder { - form: FormDefinition; + private _form: FormDefinition; constructor(initialForm: FormDefinition = nullFormDefinition) { - this.form = initialForm || nullFormDefinition; + this._form = initialForm || nullFormDefinition; + } + + get form(): FormDefinition { + return this._form; + } + + setFormSummary(summary: FormSummary) { + this._form = updateFormSummary(this.form, summary); } async addDocument(fileDetails: { name: string; data: Uint8Array }) { - //this.form = await addDocument(this.form, fileDetails); + const { updatedForm } = await addDocument(this.form, fileDetails); + this._form = updatedForm; } } diff --git a/packages/forms/src/documents/__tests__/doj-pardon-marijuana.test.ts b/packages/forms/src/documents/__tests__/doj-pardon-marijuana.test.ts index 4e9a750d..0404007a 100644 --- a/packages/forms/src/documents/__tests__/doj-pardon-marijuana.test.ts +++ b/packages/forms/src/documents/__tests__/doj-pardon-marijuana.test.ts @@ -4,12 +4,10 @@ import { Success } from '@atj/common'; import { loadSamplePDF } from './sample-data'; import { fillPDF, getDocumentFieldData } from '../pdf'; -import { FormBuilder } from '../..'; import { DocumentFieldMap } from '..'; describe('DOJ Pardon Office marijuana pardon application form', () => { it('produces valid PDF from imported PDF', async () => { - const builder = new FormBuilder(); const pdfBytes = await loadSamplePDF( 'doj-pardon-marijuana/application_for_certificate_of_pardon_for_simple_marijuana_possession.pdf' ); diff --git a/packages/forms/src/documents/document.ts b/packages/forms/src/documents/document.ts index 872dcd9a..f5b3bb8a 100644 --- a/packages/forms/src/documents/document.ts +++ b/packages/forms/src/documents/document.ts @@ -35,7 +35,6 @@ export const addDocument = async ( fields: cachedPdf.outputs, formFields: Object.fromEntries( Object.keys(cachedPdf.outputs).map(output => { - console.log(cachedPdf.outputs[output]); return [output, cachedPdf.outputs[output].name]; }) ), From dbf794cb43c68bde54cf764d15db20214ebf30af Mon Sep 17 00:00:00 2001 From: Daniel Naab Date: Thu, 21 Mar 2024 14:06:23 -0500 Subject: [PATCH 4/5] Add updateFormElement to FormBuilder --- .../design/src/FormManager/FormEdit/store.tsx | 10 ++++----- packages/forms/src/builder/index.ts | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/packages/design/src/FormManager/FormEdit/store.tsx b/packages/design/src/FormManager/FormEdit/store.tsx index 5c0ebdea..3c1f5724 100644 --- a/packages/design/src/FormManager/FormEdit/store.tsx +++ b/packages/design/src/FormManager/FormEdit/store.tsx @@ -7,7 +7,7 @@ import { type FormElementMap, type Pattern, getFormElement, - updateFormElement, + FormBuilder, FormElement, } from '@atj/forms'; import { type FormEditUIContext } from './types'; @@ -64,14 +64,14 @@ const createFormEditStore = ({ console.warn('No selected element'); return; } - const updatedForm = updateFormElement( + const builder = new FormBuilder(state.form); + const success = builder.updateFormElement( state.context.config, - state.form, state.selectedElement, formData ); - if (updatedForm) { - set({ form: updatedForm, selectedElement: undefined }); + if (success) { + set({ form: builder.form, selectedElement: undefined }); } }, })); diff --git a/packages/forms/src/builder/index.ts b/packages/forms/src/builder/index.ts index 1fc024e3..7fa4116b 100644 --- a/packages/forms/src/builder/index.ts +++ b/packages/forms/src/builder/index.ts @@ -4,6 +4,10 @@ import { addDocument, nullFormDefinition, updateFormSummary, + updateFormElement, + FormElementMap, + FormElement, + FormConfig, } from '..'; export class FormBuilder { @@ -25,4 +29,22 @@ export class FormBuilder { const { updatedForm } = await addDocument(this.form, fileDetails); this._form = updatedForm; } + + updateFormElement( + config: FormConfig, + formElement: FormElement, + formData: FormElementMap + ) { + const updatedElement = updateFormElement( + config, + this.form, + formElement, + formData + ); + if (!updatedElement) { + return false; + } + this._form = updatedElement; + return true; + } } From c24299d4f2575c35208951e75bcf88b1aa02ac31 Mon Sep 17 00:00:00 2001 From: Daniel Naab Date: Thu, 21 Mar 2024 14:08:40 -0500 Subject: [PATCH 5/5] Remove unused arguments from applyPromptResponse --- packages/design/src/Form/index.tsx | 13 ++++--------- .../form-service/src/operations/submit-form.ts | 15 ++++----------- packages/forms/src/response.ts | 3 +-- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/packages/design/src/Form/index.tsx b/packages/design/src/Form/index.tsx index a8c3c968..3cdd0bca 100644 --- a/packages/design/src/Form/index.tsx +++ b/packages/design/src/Form/index.tsx @@ -43,15 +43,10 @@ const usePrompt = ( } }; const updatePrompt = (data: Record) => { - const result = applyPromptResponse( - config, - session, - { - action: 'submit', - data, - }, - { validate: true } - ); + const result = applyPromptResponse(config, session, { + action: 'submit', + data, + }); if (!result.success) { console.warn('Error applying prompt response...', result.error); return; diff --git a/packages/form-service/src/operations/submit-form.ts b/packages/form-service/src/operations/submit-form.ts index 00cbbcbe..5c9fe47d 100644 --- a/packages/form-service/src/operations/submit-form.ts +++ b/packages/form-service/src/operations/submit-form.ts @@ -35,17 +35,10 @@ export const submitForm = async ( //const session = getSessionFromStorage(ctx.storage, sessionId) || createFormSession(form); // For now, the client-side is producing its own error messages. // In the future, we'll want this service to return errors to the client. - const newSessionResult = applyPromptResponse( - ctx.config, - session, - { - action: 'submit', - data: formData, - }, - { - validate: true, - } - ); + const newSessionResult = applyPromptResponse(ctx.config, session, { + action: 'submit', + data: formData, + }); if (!newSessionResult.success) { return Promise.resolve({ success: false, diff --git a/packages/forms/src/response.ts b/packages/forms/src/response.ts index 6e4aa4d5..88274b4e 100644 --- a/packages/forms/src/response.ts +++ b/packages/forms/src/response.ts @@ -18,8 +18,7 @@ export type PromptResponse = { export const applyPromptResponse = ( config: FormConfig, session: FormSession, - response: PromptResponse, - options: { validate: true } + response: PromptResponse ): Result => { // Get the current prompt for this session. const prompt = createPrompt(config, session, { validate: false });