UNPKG

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
# 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