verify-phone-sms 0.9.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/.env.example +20 -0
  2. package/CHANGELOG.md +71 -0
  3. package/DEPLOYMENT.md +151 -0
  4. package/README.md +475 -0
  5. package/bun.lock +1110 -0
  6. package/docs/.source/index.ts +11 -0
  7. package/docs/.source/source.config.mjs +9 -0
  8. package/docs/app/(home)/layout.tsx +7 -0
  9. package/docs/app/(home)/page.tsx +38 -0
  10. package/docs/app/docs/[[...slug]]/page.tsx +59 -0
  11. package/docs/app/docs/layout.tsx +12 -0
  12. package/docs/app/docs-og/[...slug]/route.ts +24 -0
  13. package/docs/app/globals.css +587 -0
  14. package/docs/app/layout.config.tsx +13 -0
  15. package/docs/app/layout.tsx +27 -0
  16. package/docs/app/logo.tsx +35 -0
  17. package/docs/bun.lock +923 -0
  18. package/docs/content/docs/API_AUTHENTICATION.md +91 -0
  19. package/docs/content/docs/DEPLOYMENT.md +181 -0
  20. package/docs/content/docs/api/post.mdx +35 -0
  21. package/docs/content/docs/api/verify.mdx +34 -0
  22. package/docs/content/docs/meta.json +8 -0
  23. package/docs/content/docs/verify-legal-name.md +339 -0
  24. package/docs/lib/source.ts +14 -0
  25. package/docs/mdx-components.tsx +12 -0
  26. package/docs/next.config.mjs +51 -0
  27. package/docs/openapi.json +329 -0
  28. package/docs/package.json +37 -0
  29. package/docs/postcss.config.mjs +5 -0
  30. package/docs/scripts/generate-docs.mjs +23 -0
  31. package/docs/source.config.ts +5 -0
  32. package/docs/tsconfig.json +29 -0
  33. package/docs/worker.js +35 -0
  34. package/docs/wrangler.toml +26 -0
  35. package/examples/client.ts +105 -0
  36. package/examples/demo.html +325 -0
  37. package/examples/libphonenumber-example.ts +120 -0
  38. package/openapi.json +329 -0
  39. package/package.json +75 -0
  40. package/scripts/deploy.sh +63 -0
  41. package/src/identity-verification-server.ts +677 -0
  42. package/src/index.ts +8 -0
  43. package/src/sns.ts +265 -0
  44. package/src/verify-phone-server.ts +503 -0
  45. package/src/verify-phone.ts +577 -0
  46. package/test/api.test.ts +205 -0
  47. package/test/integration.test.ts +152 -0
  48. package/test/metadata-test.ts +73 -0
  49. package/test/server.test.ts +143 -0
  50. package/test/setup.ts +32 -0
  51. package/test/utils.test.ts +186 -0
  52. package/test/verify.test.ts +20 -0
  53. package/test/voip.test.ts +113 -0
  54. package/tsconfig.json +24 -0
  55. package/vitest.config.ts +10 -0
  56. package/wrangler.toml +24 -0
@@ -0,0 +1,91 @@
1
+ ---
2
+ title: API Authentication
3
+ ---
4
+
5
+ This SMS Verification API requires authentication using an API key for all endpoints except:
6
+ - `/health` - Health check endpoint
7
+ - `/` - Swagger UI documentation (root path)
8
+ - `/openapi.json` - OpenAPI specification
9
+
10
+ ## API Key
11
+
12
+ Your API key is: `sk_test_1234567890abcdef1234567890abcdef`
13
+
14
+ ## Authentication Methods
15
+
16
+ You can provide your API key in one of two ways:
17
+
18
+ ### Method 1: X-API-Key Header (Recommended)
19
+ ```bash
20
+ curl -X POST https://your-worker.workers.dev/api/send-verification \
21
+ -H "Content-Type: application/json" \
22
+ -H "X-API-Key: sk_test_1234567890abcdef1234567890abcdef" \
23
+ -d '{"phoneNumber": "+1234567890"}'
24
+ ```
25
+
26
+ ### Method 2: Authorization Header (Bearer Token)
27
+ ```bash
28
+ curl -X POST https://your-worker.workers.dev/api/send-verification \
29
+ -H "Content-Type: application/json" \
30
+ -H "Authorization: Bearer sk_test_1234567890abcdef1234567890abcdef" \
31
+ -d '{"phoneNumber": "+1234567890"}'
32
+ ```
33
+
34
+ ## JavaScript/Node.js Examples
35
+
36
+ ### Using X-API-Key Header
37
+ ```javascript
38
+ const response = await fetch('https://your-worker.workers.dev/api/send-verification', {
39
+ method: 'POST',
40
+ headers: {
41
+ 'Content-Type': 'application/json',
42
+ 'X-API-Key': 'sk_test_1234567890abcdef1234567890abcdef'
43
+ },
44
+ body: JSON.stringify({
45
+ phoneNumber: '+1234567890'
46
+ })
47
+ });
48
+ ```
49
+
50
+ ### Using Authorization Header
51
+ ```javascript
52
+ const response = await fetch('https://your-worker.workers.dev/api/send-verification', {
53
+ method: 'POST',
54
+ headers: {
55
+ 'Content-Type': 'application/json',
56
+ 'Authorization': 'Bearer sk_test_1234567890abcdef1234567890abcdef'
57
+ },
58
+ body: JSON.stringify({
59
+ phoneNumber: '+1234567890'
60
+ })
61
+ });
62
+ ```
63
+
64
+ ## Error Responses
65
+
66
+ ### Missing API Key (401 Unauthorized)
67
+ ```json
68
+ {
69
+ "error": "API key required",
70
+ "message": "Please provide your API key in the Authorization header (Bearer token) or X-API-Key header"
71
+ }
72
+ ```
73
+
74
+ ### Invalid API Key (401 Unauthorized)
75
+ ```json
76
+ {
77
+ "error": "Invalid API key",
78
+ "message": "The provided API key is invalid"
79
+ }
80
+ ```
81
+
82
+ ## Security Notes
83
+
84
+ - Keep your API key secure and do not share it publicly
85
+ - The API key is stored as a secret in Cloudflare Workers
86
+ - All API requests should be made over HTTPS
87
+ - Consider rotating your API key periodically for enhanced security
88
+
89
+ ## Testing
90
+
91
+ You can test the API using the Swagger UI at the root path `/`, which will prompt you to enter your API key in the "Authorize" section.
@@ -0,0 +1,181 @@
1
+ ---
2
+ title: Cloudflare Workers Deployment Guide
3
+ ---
4
+
5
+ This guide will help you deploy the SMS Verification API to Cloudflare Workers using Wrangler.
6
+
7
+ ## Prerequisites
8
+
9
+ 1. **Cloudflare Account**: Sign up at [cloudflare.com](https://cloudflare.com)
10
+ 2. **Wrangler CLI**: Install Wrangler globally
11
+ ```bash
12
+ npm install -g wrangler
13
+ ```
14
+ 3. **AWS Account**: You'll need AWS credentials for SNS SMS sending
15
+
16
+ ## Setup Steps
17
+
18
+ ### 1. Install Dependencies
19
+ ```bash
20
+ npm install
21
+ ```
22
+
23
+ ### 2. Login to Cloudflare
24
+ ```bash
25
+ wrangler login
26
+ ```
27
+
28
+ ### 3. Configure AWS Credentials
29
+ Set your AWS credentials as Cloudflare Workers secrets:
30
+ ```bash
31
+ wrangler secret put AWS_ACCESS_KEY_ID
32
+ # Enter your AWS Access Key ID when prompted
33
+
34
+ wrangler secret put AWS_SECRET_ACCESS_KEY
35
+ # Enter your AWS Secret Access Key when prompted
36
+ ```
37
+
38
+ ### 4. Update Configuration
39
+ Edit `wrangler.toml` to match your Cloudflare account:
40
+ ```toml
41
+ name = "your-sms-verification-api"
42
+ main = "src/index.js"
43
+ compatibility_date = "2024-01-01"
44
+
45
+ [env.production]
46
+ name = "your-sms-verification-api"
47
+
48
+ [env.staging]
49
+ name = "your-sms-verification-api-staging"
50
+
51
+ [vars]
52
+ AWS_REGION = "us-east-1"
53
+ SMS_SENDER_ID = "YourApp"
54
+ ```
55
+
56
+ ### 5. Update Server URLs
57
+ In `src/index.js`, update the server URLs in the OpenAPI configuration:
58
+ ```javascript
59
+ servers: [
60
+ {
61
+ url: 'https://your-sms-verification-api.your-subdomain.workers.dev',
62
+ description: 'Production server',
63
+ },
64
+ {
65
+ url: 'https://your-sms-verification-api-staging.your-subdomain.workers.dev',
66
+ description: 'Staging server',
67
+ },
68
+ ],
69
+ ```
70
+
71
+ ## Development
72
+
73
+ ### Local Development
74
+ ```bash
75
+ npm run dev
76
+ ```
77
+ This starts a local development server at `http://localhost:8787`
78
+
79
+ ### Testing
80
+ ```bash
81
+ npm run test
82
+ ```
83
+
84
+ ## Deployment
85
+
86
+ ### Deploy to Staging
87
+ ```bash
88
+ npm run deploy:staging
89
+ ```
90
+
91
+ ### Deploy to Production
92
+ ```bash
93
+ npm run deploy:production
94
+ ```
95
+
96
+ ### Deploy to Default Environment
97
+ ```bash
98
+ npm run deploy
99
+ ```
100
+
101
+ ## Environment Variables
102
+
103
+ ### Required Secrets (set with `wrangler secret put`)
104
+ - `AWS_ACCESS_KEY_ID`: Your AWS Access Key ID
105
+ - `AWS_SECRET_ACCESS_KEY`: Your AWS Secret Access Key
106
+
107
+ ### Optional Variables (set in wrangler.toml)
108
+ - `AWS_REGION`: AWS region (default: us-east-1)
109
+ - `SMS_SENDER_ID`: Sender ID for SMS messages (default: Verify)
110
+
111
+ ## Production Considerations
112
+
113
+ ### 1. Use Cloudflare KV for Storage
114
+ Replace in-memory storage with Cloudflare KV for production:
115
+
116
+ ```javascript
117
+ // Add KV binding to wrangler.toml
118
+ [[kv_namespaces]]
119
+ binding = "VERIFICATION_CODES"
120
+ id = "your-kv-namespace-id"
121
+ preview_id = "your-preview-kv-namespace-id"
122
+
123
+ // Update storage in src/index.js
124
+ const verificationCodes = env.VERIFICATION_CODES;
125
+ ```
126
+
127
+ ### 2. Custom Domain
128
+ Add a custom domain in the Cloudflare dashboard and update your `wrangler.toml`:
129
+ ```toml
130
+ [env.production]
131
+ name = "your-sms-verification-api"
132
+ routes = [
133
+ { pattern = "api.yourdomain.com", zone_name = "yourdomain.com" }
134
+ ]
135
+ ```
136
+
137
+ ### 3. Rate Limiting
138
+ Consider using Cloudflare's built-in rate limiting or implement more sophisticated rate limiting with KV storage.
139
+
140
+ ## Monitoring
141
+
142
+ ### Logs
143
+ View logs in the Cloudflare dashboard or using Wrangler:
144
+ ```bash
145
+ wrangler tail
146
+ ```
147
+
148
+ ### Analytics
149
+ Monitor your API usage in the Cloudflare dashboard under Workers & Pages.
150
+
151
+ ## Troubleshooting
152
+
153
+ ### Common Issues
154
+
155
+ 1. **CORS Errors**: The API is configured to allow all origins (`*`). Adjust in `src/index.js` if needed.
156
+
157
+ 2. **AWS Credentials**: Ensure your AWS credentials have SNS SMS sending permissions.
158
+
159
+ 3. **Memory Limits**: Cloudflare Workers have memory limits. The current implementation uses in-memory storage which resets on each request.
160
+
161
+ 4. **Timeout Issues**: Workers have a 30-second timeout. Ensure your SNS requests complete within this time.
162
+
163
+ ### Debug Mode
164
+ Enable debug logging by setting the log level in your Worker:
165
+ ```javascript
166
+ app.use('*', logger({ level: 'debug' }));
167
+ ```
168
+
169
+ ## Security
170
+
171
+ - AWS credentials are stored as encrypted secrets
172
+ - CORS is configured for cross-origin requests
173
+ - Rate limiting is implemented to prevent abuse
174
+ - Input validation is performed on all endpoints
175
+
176
+ ## Cost Optimization
177
+
178
+ - Cloudflare Workers are pay-per-request
179
+ - Monitor your usage in the Cloudflare dashboard
180
+ - Consider implementing caching for frequently accessed data
181
+ - Use KV storage efficiently to minimize read/write operations
@@ -0,0 +1,35 @@
1
+ ---
2
+ title: Send SMS verification code
3
+ ---
4
+
5
+
6
+ ![phone_logo](https://i.imgur.com/2adfBGT.png)
7
+
8
+
9
+ A comprehensive SMS verification API using AWS SNS HTTP API with Hono server on Cloudflare Workers. The API is fully documented and driven by an OpenAPI 3.0 spec, available at:
10
+ ## Features
11
+ - **Cloudflare Workers**: Serverless deployment with global edge network
12
+ - **Modern OpenAPI-driven contract**: Fully documented API with Swagger UI
13
+ - **SMS verification with optional custom code**: Send random or custom verification codes
14
+ - **VoIP number blocking**: Optional protection against VoIP numbers using phone lookup API
15
+ - **Code verification endpoint**: Verify submitted codes with attempt tracking
16
+ - **Health check endpoint**: Monitor API status
17
+ - **API Key Authentication**: Secure access control for all endpoints
18
+ - **Strong input validation**: E.164 phone numbers, 6-digit codes
19
+ - **Rate limiting and error handling**: Built-in protection against abuse
20
+ - **More info like names, emails**: See [Trestle](https://trestle-api.redoc.ly/Current/#section/Overview)
21
+ - **MIT licensed**: Open source and free to use
22
+
23
+
24
+
25
+ #### Send Verification Code
26
+ `GET /api/send-verification`
27
+ - Sends a 6-digit verification code to the specified phone number via SMS.
28
+ - Optionally accepts a custom code (for testing or admin use).
29
+ - Optionally blocks VoIP numbers using phone lookup API.
30
+
31
+ **Query Parameters:**
32
+ - `phoneNumber` (required): Phone number in E.164 format (e.g., +1234567890)
33
+ - `code` (optional): Custom 6-digit verification code
34
+ - `blockVoip` (optional): Boolean flag to block VoIP numbers
35
+ <APIPage document={"openapi.json"} operations={[{"path":"/api/send-verification","method":"post"}]} webhooks={[]} hasHead={false} />
@@ -0,0 +1,34 @@
1
+ ---
2
+ title: Verify SMS code
3
+ ---
4
+
5
+ #### Verify Code
6
+ `GET /api/verify-code`
7
+ - Verifies the submitted code against the sent verification code.
8
+
9
+ **Query Parameters:**
10
+ - `phoneNumber` (required): Phone number in E.164 format
11
+ - `code` (required): 6-digit verification code
12
+
13
+ **Example Request:**
14
+ ```
15
+ GET /api/verify-code?phoneNumber=%2B1234567890&code=654321
16
+ ```
17
+
18
+ **Response (success):**
19
+ ```json
20
+ {
21
+ "success": true,
22
+ "message": "Phone number verified successfully",
23
+ "verificationToken": "unique-verification-token",
24
+ "phoneNumber": "+1234567890"
25
+ }
26
+ ```
27
+
28
+ **Response (error):**
29
+ ```json
30
+ {
31
+ "error": "Invalid verification code",
32
+ "attemptsRemaining": 3
33
+ }
34
+ ```
@@ -0,0 +1,8 @@
1
+ {
2
+ "pages": [
3
+ "api/post",
4
+ "api/verify",
5
+ "..."
6
+
7
+ ]
8
+ }
@@ -0,0 +1,339 @@
1
+ ---
2
+ title: Identity Verification API Demo
3
+ ---
4
+
5
+ A comprehensive identity verification system that uses TrestleIQ APIs to validate phone numbers, addresses, and generate knowledge-based authentication questions.
6
+
7
+ ## 🚀 Quick Start
8
+
9
+ ### Prerequisites
10
+ - Node.js or Bun runtime
11
+ - TrestleIQ API key
12
+
13
+ ### Installation
14
+ ```bash
15
+ # Install dependencies
16
+ npm install hono @hono/zod-openapi zod
17
+ # or
18
+ bun add hono @hono/zod-openapi zod
19
+
20
+ # Set your TrestleIQ API key
21
+ export TRESTLE_API_KEY=your_api_key_here
22
+
23
+ # Run the server
24
+ bun run server.js
25
+ # or
26
+ node server.js
27
+ ```
28
+
29
+ ### Server Endpoints
30
+ - 🏠 `http://localhost:3000` - Server root
31
+ - 📊 `http://localhost:3000/health` - Health check
32
+ - 📚 `http://localhost:3000/swagger` - Interactive API documentation
33
+ - 🔍 `http://localhost:3000/doc` - OpenAPI specification
34
+ - 🎮 `http://localhost:3000/demo` - Live demo with sample data
35
+ - ✅ `POST http://localhost:3000/verify-identity` - Main verification endpoint
36
+
37
+ ## 🎯 How It Works
38
+
39
+ ### The Verification Process
40
+
41
+ 1. **Input Collection**: Accept phone number, legal name, and current address
42
+ 2. **Multi-API Lookup**: Query TrestleIQ APIs in parallel for comprehensive data
43
+ 3. **Historical Analysis**: Extract previous addresses, phone numbers, and associated names
44
+ 4. **Scoring Algorithm**: Calculate confidence score (0-100) based on data matches
45
+ 5. **Question Generation**: Create knowledge-based questions from historical data
46
+ 6. **Recommendations**: Provide actionable next steps based on verification results
47
+
48
+ ### Scoring System (100 Points Total)
49
+
50
+ | Category | Max Points | Criteria |
51
+ |----------|------------|----------|
52
+ | **Phone Validation** | 30 | Valid number (15 pts) + Line type (10 pts) + Non-commercial (5 pts) |
53
+ | **Name Matching** | 40 | Exact match (40 pts) or Partial match (20 pts) |
54
+ | **Address Validation** | 30 | Valid address (15 pts) + Active delivery (10 pts) + Residential (5 pts) |
55
+
56
+ ### Score Interpretation
57
+ - **🔴 0-29**: High risk - Request additional ID documents
58
+ - **🟡 30-59**: Medium risk - Manual review recommended
59
+ - **🟢 60-79**: Low risk - Standard verification process
60
+ - **✅ 80-100**: Very low risk - High confidence verification
61
+
62
+ ## 📝 API Usage Examples
63
+
64
+ ### Sample Request
65
+ ```bash
66
+ curl -X POST http://localhost:3000/verify-identity \
67
+ -H "Content-Type: application/json" \
68
+ -d '{
69
+ "phone_number": "2069735100",
70
+ "legal_name": "John Smith",
71
+ "current_address": {
72
+ "street_line_1": "123 Main St",
73
+ "city": "Seattle",
74
+ "state_code": "WA",
75
+ "postal_code": "98101",
76
+ "country_code": "US"
77
+ }
78
+ }'
79
+ ```
80
+
81
+ ### Sample Response
82
+ ```json
83
+ {
84
+ "verification_score": 75,
85
+ "name_match_found": true,
86
+ "phone_validated": true,
87
+ "address_validated": true,
88
+ "questions": [
89
+ {
90
+ "id": "addr_1703123456789",
91
+ "question": "Which of the following addresses have you lived at in the past?",
92
+ "type": "address_history",
93
+ "options": [
94
+ "456 Oak Ave, Seattle, WA",
95
+ "789 Pine St, Tacoma, WA",
96
+ "123 Fake St, Nowhere, CA",
97
+ "101 False Blvd, Bogus, NY",
98
+ "202 Phony Way, Unreal, WA"
99
+ ]
100
+ },
101
+ {
102
+ "id": "phone_1703123456790",
103
+ "question": "Which of the following phone numbers have you previously used?",
104
+ "type": "phone_history",
105
+ "options": [
106
+ "2065551234",
107
+ "4255559876",
108
+ "5551234567",
109
+ "8889876543",
110
+ "None of the above"
111
+ ]
112
+ },
113
+ {
114
+ "id": "name_1703123456791",
115
+ "question": "Are any of the following names associated with you (maiden name, nickname, etc.)?",
116
+ "type": "name_verification",
117
+ "options": [
118
+ "J. Smith",
119
+ "Johnny Smith",
120
+ "John S. Smith",
121
+ "Jon Smith",
122
+ "None of the above"
123
+ ]
124
+ }
125
+ ],
126
+ "historical_data": {
127
+ "previous_addresses": [
128
+ "456 Oak Ave, Seattle, WA",
129
+ "789 Pine St, Tacoma, WA",
130
+ "321 Cedar Ln, Bellevue, WA"
131
+ ],
132
+ "previous_phones": [
133
+ "2065551234",
134
+ "4255559876"
135
+ ],
136
+ "associated_names": [
137
+ "J. Smith",
138
+ "Johnny Smith",
139
+ "John S. Smith"
140
+ ]
141
+ },
142
+ "recommendations": [
143
+ "Proceed with standard verification process",
144
+ "Consider asking verification questions to increase confidence"
145
+ ]
146
+ }
147
+ ```
148
+
149
+ ## 🧠 Smart Features
150
+
151
+ ### Dynamic Question Generation
152
+ The system intelligently creates multiple-choice questions by:
153
+ - **Mixing real historical data** with plausible decoy options
154
+ - **Randomizing question order** to prevent pattern recognition
155
+ - **Balancing difficulty** - not too easy, not impossible
156
+ - **Including safety options** like "None of the above"
157
+
158
+ ### Historical Data Analysis
159
+ Extracts comprehensive historical information:
160
+ - **Previous addresses** from phone and person records
161
+ - **Associated phone numbers** across different time periods
162
+ - **Name variations** including nicknames, initials, and maiden names
163
+ - **Cross-references data** across multiple API sources for accuracy
164
+
165
+ ### Risk-Based Recommendations
166
+ Provides actionable recommendations based on verification results:
167
+ - **Document requests** for low-scoring verifications
168
+ - **VOIP warnings** for non-fixed internet phone numbers
169
+ - **Manual review triggers** for medium-confidence scores
170
+ - **Approval suggestions** for high-confidence verifications
171
+
172
+ ## 🔧 Advanced Configuration
173
+
174
+ ### Environment Variables
175
+ ```bash
176
+ TRESTLE_API_KEY=your_trestle_api_key # Required: TrestleIQ API key
177
+ PORT=3000 # Optional: Server port (default: 3000)
178
+ ```
179
+
180
+ ### Custom Scoring Weights
181
+ You can modify the scoring algorithm by adjusting the point values in the `calculateVerificationScore` function:
182
+
183
+ ```javascript
184
+ // Phone validation scoring
185
+ if (phoneResult?.is_valid) {
186
+ score += 15 // Base validation points
187
+ if (phoneResult.line_type === 'Mobile' || phoneResult.line_type === 'Landline') {
188
+ score += 10 // Reliable line type bonus
189
+ }
190
+ if (!phoneResult.is_commercial) {
191
+ score += 5 // Residential number bonus
192
+ }
193
+ }
194
+ ```
195
+
196
+ ### Question Customization
197
+ Modify question generation in `generateVerificationQuestions`:
198
+ - Adjust number of real vs. fake options
199
+ - Change question phrasing
200
+ - Add new question types
201
+ - Customize difficulty levels
202
+
203
+ ## 🎮 Try the Demo
204
+
205
+ Visit `http://localhost:3000/demo` to see a live example with sample data, or use the interactive Swagger UI at `http://localhost:3000/swagger` to test with your own data.
206
+
207
+ ### Demo Scenarios
208
+
209
+ #### High Confidence Scenario (Score: 85+)
210
+ ```json
211
+ {
212
+ "phone_number": "2069735100",
213
+ "legal_name": "Waidong L Syrws",
214
+ "current_address": {
215
+ "street_line_1": "100 Syrws St",
216
+ "city": "Lynden",
217
+ "state_code": "WA",
218
+ "postal_code": "98264"
219
+ }
220
+ }
221
+ ```
222
+
223
+ #### Medium Confidence Scenario (Score: 50-70)
224
+ ```json
225
+ {
226
+ "phone_number": "5551234567",
227
+ "legal_name": "Jane Doe",
228
+ "current_address": {
229
+ "street_line_1": "789 Unknown Ave",
230
+ "city": "Somewhere",
231
+ "state_code": "CA",
232
+ "postal_code": "90210"
233
+ }
234
+ }
235
+ ```
236
+
237
+ #### Low Confidence Scenario (Score: 20-40)
238
+ ```json
239
+ {
240
+ "phone_number": "1234567890",
241
+ "legal_name": "Fake Person",
242
+ "current_address": {
243
+ "street_line_1": "123 Nonexistent St",
244
+ "city": "Nowhere",
245
+ "state_code": "XX",
246
+ "postal_code": "00000"
247
+ }
248
+ }
249
+ ```
250
+
251
+ ## 🛡️ Security & Privacy
252
+
253
+ - **No data storage**: All verification data is processed in-memory only
254
+ - **API key protection**: TrestleIQ API key stored securely in environment variables
255
+ - **CORS enabled**: Configurable cross-origin request handling
256
+ - **Error handling**: Comprehensive error handling without data leakage
257
+ - **Rate limiting**: Inherits TrestleIQ API rate limits for responsible usage
258
+
259
+ ## 🔗 Integration Examples
260
+
261
+ ### React Frontend Integration
262
+ ```javascript
263
+ const verifyIdentity = async (personData) => {
264
+ const response = await fetch('/verify-identity', {
265
+ method: 'POST',
266
+ headers: { 'Content-Type': 'application/json' },
267
+ body: JSON.stringify(personData)
268
+ })
269
+ return response.json()
270
+ }
271
+
272
+ // Usage
273
+ const result = await verifyIdentity({
274
+ phone_number: "2069735100",
275
+ legal_name: "John Smith",
276
+ current_address: { /* address data */ }
277
+ })
278
+
279
+ if (result.verification_score >= 80) {
280
+ // High confidence - proceed with onboarding
281
+ } else if (result.questions.length > 0) {
282
+ // Show verification questions
283
+ } else {
284
+ // Request additional documentation
285
+ }
286
+ ```
287
+
288
+ ### Node.js Backend Integration
289
+ ```javascript
290
+ import { verifyIdentity } from './verification-functions.js'
291
+
292
+ app.post('/onboard-user', async (req, res) => {
293
+ try {
294
+ const verification = await verifyIdentity(req.body, process.env.TRESTLE_API_KEY)
295
+
296
+ // Store verification result
297
+ await db.users.update(req.body.userId, {
298
+ verification_score: verification.verification_score,
299
+ verification_status: verification.verification_score >= 70 ? 'approved' : 'pending',
300
+ questions: verification.questions
301
+ })
302
+
303
+ res.json(verification)
304
+ } catch (error) {
305
+ res.status(500).json({ error: 'Verification failed' })
306
+ }
307
+ })
308
+ ```
309
+
310
+ ## 📊 API Response Details
311
+
312
+ ### Verification Questions Types
313
+ - **`address_history`**: Multiple choice questions about previous addresses
314
+ - **`phone_history`**: Questions about previously used phone numbers
315
+ - **`name_verification`**: Questions about name variations and associations
316
+
317
+ ### Recommendation Categories
318
+ - **Identity Documents**: When additional ID verification is needed
319
+ - **Manual Review**: When human verification should be considered
320
+ - **Technical Warnings**: VOIP numbers, invalid addresses, etc.
321
+ - **Process Guidance**: Next steps based on confidence level
322
+
323
+ ## 🤝 Contributing
324
+
325
+ This demo showcases the core functionality. For production use, consider:
326
+ - Adding database persistence for verification results
327
+ - Implementing user authentication and session management
328
+ - Adding webhook support for async verification workflows
329
+ - Enhancing question complexity and variety
330
+ - Adding support for international phone numbers and addresses
331
+
332
+ ## 📞 Support
333
+
334
+ For TrestleIQ API questions, visit [TrestleIQ Documentation](https://api.trestleiq.com)
335
+ For implementation questions, check the inline code comments and Swagger documentation.
336
+
337
+ ---
338
+
339
+ **Ready to verify identities?** Start the server and visit the demo endpoint! 🎯
@@ -0,0 +1,14 @@
1
+ import { createMDXSource } from 'fumadocs-mdx';
2
+ import { loader } from 'fumadocs-core/source';
3
+ import { attachFile, createOpenAPI } from 'fumadocs-openapi/server';
4
+ import { docs, meta } from '@/.source';
5
+
6
+ export const source = loader({
7
+ baseUrl: '/docs',
8
+ source: createMDXSource(docs, meta),
9
+ pageTree: {
10
+ attachFile,
11
+ },
12
+ });
13
+
14
+ export const openapi = createOpenAPI();