triostack-document-common-sdk
Version:
Generate professional proposals and legal agreements using OpenAI API with support for PDF and DOC formats
193 lines (147 loc) โข 5.04 kB
Markdown
# Test UI for Triostack Document SDK
A simple web interface to test the CommonJS module functionality of the Triostack Document SDK.
## ๐ Project Structure
```
test-ui/
โโโ modules/
โ โโโ document-generator.js # CommonJS module copy
โโโ public/
โ โโโ index.html # Web interface
โโโ src/
โ โโโ server.js # Express server
โโโ package.json # Dependencies
โโโ README.md # This file
```
## ๐ Quick Start
### 1. Install Dependencies
```bash
cd test-ui
npm install
```
### 2. Start the Server
```bash
npm start
```
Or for development with auto-restart:
```bash
npm run dev
```
### 3. Open the Test UI
Navigate to `http://localhost:3001` in your browser.
## ๐งช Testing Features
### Module Status Check
- โ
Verifies all 8 functions are available
- โ
Tests CommonJS module loading
- โ
Shows function availability status
### Proposal Generation
- ๐ Generate text proposals
- ๐ Generate proposal PDFs
- ๐ Uses OpenAI API (requires valid API key)
### Agreement Generation
- โ๏ธ Generate text agreements
- ๐ Generate agreement PDFs
- ๐ Uses OpenAI API (requires valid API key)
### Document Generation
- ๐ Convert text to PDF
- ๐ Convert text to DOC
- ๐ฏ No API key required for these tests
## ๐ง API Endpoints
### Module Test
- `GET /api/test` - Test module loading and function availability
### Proposal Generation
- `POST /api/generate-proposal` - Generate text proposal
- `POST /api/generate-proposal-pdf` - Generate proposal PDF
### Agreement Generation
- `POST /api/generate-agreement` - Generate text agreement
- `POST /api/generate-agreement-pdf` - Generate agreement PDF
### Document Generation
- `POST /api/generate-pdf` - Convert text to PDF
- `POST /api/generate-doc` - Convert text to DOC
## ๐ Usage Instructions
### 1. Module Testing
- Click "Test Module Loading" to verify the CommonJS module works
- Should show all 8 functions as available
### 2. Proposal Testing
- Enter your OpenAI API key
- Fill in project details, name, and pricing
- Click "Generate Proposal" for text or "Generate Proposal PDF" for PDF
### 3. Agreement Testing
- Enter your OpenAI API key
- Fill in all required fields including Party A and Party B
- Click "Generate Agreement" for text or "Generate Agreement PDF" for PDF
### 4. Document Generation Testing
- Enter any text content
- Specify a filename (optional)
- Click "Generate PDF" or "Generate DOC" to test document conversion
## ๐ What This Tests
### CommonJS Compatibility
- โ
Module loading with `require()`
- โ
Function exports with `module.exports`
- โ
All dependencies (OpenAI, jsPDF, docx)
### Function Availability
- โ
`generateProposal`
- โ
`generateAgreement`
- โ
`generatePDF`
- โ
`generateDOC`
- โ
`generateProposalPDF`
- โ
`generateProposalDOC`
- โ
`generateAgreementPDF`
- โ
`generateAgreementDOC`
### Document Generation
- โ
PDF creation with company header
- โ
DOC creation with proper formatting
- โ
File download functionality
- โ
Error handling
## ๐ ๏ธ Troubleshooting
### Module Not Loading
- Check that `modules/document-generator.js` exists
- Verify all dependencies are installed
- Check Node.js version (14+ required)
### API Errors
- Ensure OpenAI API key is valid
- Check internet connection
- Verify API key has sufficient credits
### File Download Issues
- Check browser download settings
- Ensure popup blockers are disabled
- Verify file permissions
## ๐ Expected Results
### Module Test
```
โ
Module Loaded Successfully
Available Functions (8/8):
- generateProposal
- generateAgreement
- generatePDF
- generateDOC
- generateProposalPDF
- generateProposalDOC
- generateAgreementPDF
- generateAgreementDOC
```
### Document Generation
- PDF files should include Triostack company header
- DOC files should be properly formatted
- Files should download automatically
## ๐ง Development
### Adding New Tests
1. Add new endpoint in `src/server.js`
2. Add corresponding UI section in `public/index.html`
3. Add JavaScript function for the test
### Modifying the Module
1. Update `modules/document-generator.js`
2. Restart the server
3. Test the changes through the UI
## ๐ Notes
- This test UI is for development and testing purposes only
- It uses the same CommonJS module structure as the main package
- All generated files include the Triostack company branding
- The UI provides real-time feedback on module functionality
## ๐ฏ Success Criteria
The test UI is working correctly when:
- โ
Module loads without errors
- โ
All 8 functions are available
- โ
PDF generation works (with company header)
- โ
DOC generation works (with proper formatting)
- โ
File downloads work correctly
- โ
Error handling works properly