Skip to content

Commit 539999d

Browse files
committed
feat: add support for API key authentication alongside JWT tokens
1 parent 03feb43 commit 539999d

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

examples/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,22 @@ const API_BASE_URL = 'http://localhost:3000'; // Change as needed
100100

101101
### Authentication
102102

103-
Replace the placeholder token in each example:
103+
There are two ways to authenticate with the API:
104+
105+
1. **JWT Tokens** - Use the Authorization header with Bearer prefix:
106+
107+
```javascript
108+
'Authorization': 'Bearer YOUR_JWT_TOKEN_HERE'
109+
```
110+
111+
2. **API Keys** - Use the X-API-Key header:
104112

105113
```javascript
106-
'Authorization': 'Bearer YOUR_ACTUAL_TOKEN_HERE'
114+
'X-API-Key': 'YOUR_API_KEY_HERE' // API keys start with 'pfs_'
107115
```
108116

117+
> **Important**: API keys should be sent in the X-API-Key header, not in the Authorization header.
118+
109119
### File Paths
110120

111121
Update file paths to point to your actual documents:
@@ -154,7 +164,10 @@ Each example will:
154164

155165
### Common Issues
156166

157-
1. **Authentication Error**: Check your bearer token
167+
1. **Authentication Error**:
168+
- For JWT tokens: Ensure your token is valid and sent in the Authorization header
169+
- For API keys: Make sure to use the X-API-Key header (not Authorization) for API keys
170+
- API keys should start with 'pfs_' and be sent without any 'Bearer' prefix
158171
2. **Server Connection**: Verify the API_BASE_URL and server status
159172
3. **File Not Found**: Check file paths and permissions
160173
4. **Conversion Failed**: Some formats have limitations (see above)

examples/test-document-to-markdown-endpoints.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ async function testPdfToMarkdown() {
2727
method: 'POST',
2828
headers: {
2929
'Content-Type': 'application/json',
30-
'Authorization': 'Bearer YOUR_AUTH_TOKEN' // Replace with actual token
30+
// Use one of the following authentication methods:
31+
// 1. For JWT tokens:
32+
'Authorization': 'Bearer YOUR_JWT_TOKEN', // Replace with actual JWT token
33+
// 2. For API keys (comment out the Authorization header above and use this instead):
34+
// 'X-API-Key': 'YOUR_API_KEY' // Replace with actual API key (starts with pfs_)
3135
},
3236
body: JSON.stringify({
3337
file: testPdfBase64,
@@ -270,7 +274,10 @@ async function runTests() {
270274

271275
console.log('\n✨ All tests completed!');
272276
console.log('\nNote: To run actual tests, you need to:');
273-
console.log('1. Replace YOUR_AUTH_TOKEN with a valid authentication token');
277+
console.log('1. Choose an authentication method:');
278+
console.log(' a. For JWT tokens: Replace YOUR_JWT_TOKEN with a valid JWT token');
279+
console.log(' b. For API keys: Comment out the Authorization header and uncomment the X-API-Key header');
280+
console.log(' Then replace YOUR_API_KEY with a valid API key (starts with pfs_)');
274281
console.log('2. Replace the test base64 content with actual file content');
275282
console.log('3. Ensure the server is running on the correct port');
276283
}

examples/xlsx-to-markdown-example.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ async function convertXlsxToMarkdown(xlsxBase64, filename, store = false) {
3232
method: 'POST',
3333
headers: {
3434
'Content-Type': 'application/json',
35-
'Authorization': 'Bearer YOUR_AUTH_TOKEN' // Replace with actual token
35+
// Use one of the following authentication methods:
36+
// 1. For JWT tokens:
37+
'Authorization': 'Bearer YOUR_JWT_TOKEN', // Replace with actual JWT token
38+
// 2. For API keys (comment out the Authorization header above and use this instead):
39+
// 'X-API-Key': 'YOUR_API_KEY' // Replace with actual API key (starts with pfs_)
3640
},
3741
body: JSON.stringify({
3842
file: xlsxBase64,
@@ -95,7 +99,10 @@ async function runExample() {
9599
console.log('🧪 XLSX to Markdown Conversion Example\n');
96100

97101
console.log('📋 Setup Instructions:');
98-
console.log('1. Replace YOUR_AUTH_TOKEN with a valid authentication token');
102+
console.log('1. Choose an authentication method:');
103+
console.log(' a. For JWT tokens: Replace YOUR_JWT_TOKEN with a valid JWT token');
104+
console.log(' b. For API keys: Comment out the Authorization header and uncomment the X-API-Key header');
105+
console.log(' Then replace YOUR_API_KEY with a valid API key (starts with pfs_)');
99106
console.log('2. Place an XLSX file named "sample-spreadsheet.xlsx" in this directory, or');
100107
console.log('3. Replace sampleXlsxBase64 with actual XLSX content in base64 format');
101108
console.log('4. Ensure the server is running on the correct port\n');

0 commit comments

Comments
 (0)