# Echomark Setup Guide

**Quick Reference**: Steps to configure Echomark integration after your API server meeting

---

## After Your Echomark Meeting

You'll receive from Echomark:
1. **API Server URL** (e.g., `https://echomark.yourcompany.com:5344`)
2. **Admin URL** (optional, for management)
3. **Bearer Token** (if authentication is enabled)
4. **Docker deployment instructions** (if self-hosting)

---

## Configuration Steps

### Step 1: Update API Client

**File**: [src/lib/echomark-client.js](../src/lib/echomark-client.js#L11)

```javascript
// BEFORE (line 11):
this.apiUrl = apiUrl || 'http://localhost:5344'; // Default for local testing

// AFTER:
this.apiUrl = apiUrl || 'https://echomark.yourcompany.com:5344'; // Your production URL
```

**With Authentication** (if Echomark provides a token):

```javascript
// BEFORE (line 12):
this.apiToken = apiToken; // Bearer token if authentication is enabled

// AFTER (line 282):
export const echomarkClient = new EchomarkClient(
  'https://echomark.yourcompany.com:5344',
  'your_bearer_token_here'  // Add the token here
);
```

### Step 2: Update manifest.json (if using different domain)

**File**: [manifest.json](../manifest.json#L17-22)

If your Echomark server is on a different domain, add it to `host_permissions`:

```json
"host_permissions": [
  "https://*.filevineapp.com/*",
  "https://api.filevineapp.com/*",
  "https://identity.filevine.com/*",
  "https://*.amazonaws.com/*",
  "https://echomark.yourcompany.com/*"  // Add your Echomark domain
],
```

### Step 3: Test Connection

1. Load the extension in Chrome
2. Open browser console (F12)
3. Run this test:

```javascript
// Test health endpoint
fetch('https://echomark.yourcompany.com:5344/health')
  .then(r => {
    if (r.ok) {
      console.log('✅ Echomark API is reachable');
    } else {
      console.error('❌ Echomark API error:', r.status);
    }
  })
  .catch(e => console.error('❌ Network error:', e));

// Test from extension
const baseUrl = chrome.runtime.getURL('');
import(`${baseUrl}src/lib/echomark-client.js`).then(module => {
  module.echomarkClient.testConnection().then(ok => {
    console.log(ok ? '✅ Extension can reach Echomark' : '❌ Extension cannot reach Echomark');
  });
});
```

### Step 4: Test Watermarking

1. Navigate to a Filevine project with PDF or image files
2. Click "Protect" button next to a file
3. Fill in test recipient:
   - Name: "Test User"
   - Email: "test@yourcompany.com"
4. Click "Protect Document"
5. **Expected**: Download should start after 5-10 seconds
6. **Expected**: Green notification: "Document protected for Test User"

### Step 5: Verify Storage

1. Open Chrome DevTools (F12)
2. Go to: **Application** → **Storage** → **IndexedDB** → **EchomarkDB**
3. Check **marking_schemas** store
   - Should have 1 record with your test data
4. Check **watermarked_documents** store
   - Should have 1 record with the watermarked blob

---

## Troubleshooting

### Issue: "Network error" when testing

**Cause**: CORS or network connectivity issue

**Solutions**:
1. Check if Echomark server is running: `curl https://echomark.yourcompany.com:5344/health`
2. Verify CORS is enabled on Echomark server
3. Check firewall rules allow Chrome to access the server
4. Verify SSL certificate is valid (or use `http://` for testing)

### Issue: "401 Unauthorized"

**Cause**: Bearer token missing or incorrect

**Solutions**:
1. Verify token in `echomark-client.js:282`
2. Check token format: Should be just the token, NOT "Bearer token_here"
3. Regenerate token from Echomark admin panel

### Issue: "Expected multipart/form-data response"

**Cause**: Echomark API response format mismatch

**Solutions**:
1. Verify Echomark API version is v2.0.3 or later
2. Check Echomark server logs for errors
3. Contact Echomark support

---

## Optional: Add Settings UI

For easier configuration without code changes, you can add a settings page:

**Future Enhancement** (not yet implemented):

```javascript
// Create src/settings/settings.html
// Allow users to input:
// - Echomark API URL
// - Bearer Token
// - Default watermark strength
// Store in chrome.storage.sync
```

---

## Production Checklist

Before rolling out to users:

- [ ] Echomark API server deployed and accessible
- [ ] API URL updated in `echomark-client.js`
- [ ] Bearer token configured (if required)
- [ ] Health check passes from extension
- [ ] Test watermarking with sample PDF
- [ ] Test watermarking with sample image
- [ ] Verify IndexedDB storage works
- [ ] Verify download to user's machine works
- [ ] Test with large files (10+ MB)
- [ ] Document internal Echomark server details for team

---

## Quick Reference

| What | Where | Line |
|------|-------|------|
| API URL | `src/lib/echomark-client.js` | 11 |
| Bearer Token | `src/lib/echomark-client.js` | 282 |
| Host Permissions | `manifest.json` | 17-22 |
| Test Connection | Browser Console | See Step 3 |
| Documentation | `docs/ECHOMARK_INTEGRATION.md` | - |

---

**Need Help?**

- See full documentation: [ECHOMARK_INTEGRATION.md](ECHOMARK_INTEGRATION.md)
- Echomark API docs: [Echomark API Documentation.pdf](../Echomark%20API%20Documentation%20(1).pdf)
- Check console logs with `[Echomark]` prefix
- Open background service worker console: `chrome://extensions/` → "Service worker"

---

**Last Updated**: 2026-01-12
