verify-phone-sms 0.9.60 → 0.9.61

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 (2) hide show
  1. package/README.md +524 -513
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,513 +1,524 @@
1
- # SMS Verification API Server
2
-
3
- <p align="center">
4
- <a href="https://www.npmjs.com/package/verify-phone-sms"><img src="https://img.shields.io/npm/dm/verify-phone-sms.svg" alt="NPM Monthly Downloads" /></a>
5
- <a href="https://www.npmjs.com/package/verify-phone-sms"><img src="https://img.shields.io/npm/dt/verify-phone-sms.svg" alt="NPM Total Downloads" /></a>
6
- <a href="https://www.npmjs.com/package/verify-phone-sms"><img src="https://img.shields.io/npm/v/verify-phone-sms.svg" alt="npm version" /></a>
7
- <a href="https://github.com/OpenSourceAGI/dev-tools-starter-agent/blob/master/LICENSE.md"><img src="https://img.shields.io/npm/l/verify-phone-sms.svg" alt="license" /></a>
8
- </p>
9
-
10
- A complete Hono-based server for SMS verification using AWS SNS. Built for Cloudflare Workers with comprehensive API documentation and security features.
11
-
12
- ## Features
13
-
14
- - ✅ **SMS Verification**: Send verification codes via AWS SNS
15
- - ✅ **VoIP Blocking**: Optional blocking of VoIP numbers
16
- - ✅ **API Authentication**: Secure API key-based authentication
17
- - ✅ **Rate Limiting**: Built-in rate limiting protection
18
- - ✅ **OpenAPI Documentation**: Auto-generated API documentation
19
- - ✅ **CORS Support**: Cross-origin resource sharing enabled
20
- - ✅ **Security Headers**: Secure headers middleware
21
- - ✅ **Error Handling**: Comprehensive error handling
22
- - ✅ **Health Checks**: Built-in health monitoring
23
- - ✅ **General SMS**: Send custom SMS messages
24
-
25
-
26
-
27
- ## Quick Start
28
-
29
- ### 1. Install
30
-
31
- ```bash
32
- npm install verify-phone-sms # use verifyPhone() from your own backend
33
- ```
34
-
35
- Or clone the repo and install its dependencies to run the server itself:
36
-
37
- ```bash
38
- npm install
39
- ```
40
-
41
- ### 2. Set Environment Variables
42
-
43
- Create a `.env` file or set environment variables:
44
-
45
- ```bash
46
- # AWS Credentials
47
- AWS_ACCESS_KEY_ID=your_aws_access_key
48
- AWS_SECRET_ACCESS_KEY=your_aws_secret_key
49
- AWS_REGION=us-east-1
50
-
51
- # API Configuration
52
- API_KEY=sms_1234567890abcdef1234567890abcdef
53
- SMS_SENDER_ID=Verify
54
- ```
55
-
56
- ### 3. Run Development Server
57
-
58
- ```bash
59
- npm run dev
60
- ```
61
-
62
- The server will be available at `http://localhost:8787`
63
-
64
- ### 4. Deploy to Cloudflare Workers
65
-
66
- ```bash
67
- # Deploy API only
68
- npm run deploy
69
-
70
- # Deploy docs only
71
- npm run build:docs
72
- npm run deploy:docs
73
-
74
- # Deploy both API and docs
75
- npm run deploy:all
76
-
77
- # Deploy to specific environments
78
- npm run deploy:staging
79
- npm run deploy:production
80
- npm run deploy:all:staging
81
- npm run deploy:all:production
82
- ```
83
-
84
- ### 5. Quick Deployment Script
85
-
86
- ```bash
87
- # Deploy everything to default environment
88
- ./scripts/deploy.sh
89
-
90
- # Deploy to staging
91
- ./scripts/deploy.sh staging
92
-
93
- # Deploy to production
94
- ./scripts/deploy.sh production
95
-
96
- # Deploy only API
97
- ./scripts/deploy.sh default api
98
-
99
- # Deploy only docs
100
- ./scripts/deploy.sh default docs
101
- ```
102
-
103
- ## Deployment
104
-
105
- ### Prerequisites
106
-
107
- 1. **Install Wrangler CLI**:
108
- ```bash
109
- npm install -g wrangler
110
- ```
111
-
112
- 2. **Login to Cloudflare**:
113
- ```bash
114
- wrangler login
115
- ```
116
-
117
- 3. **Set Secrets**:
118
- ```bash
119
- wrangler secret put AWS_ACCESS_KEY_ID
120
- wrangler secret put AWS_SECRET_ACCESS_KEY
121
- wrangler secret put API_KEY
122
- ```
123
-
124
- ### Environment Configuration
125
-
126
- The project supports multiple deployment environments:
127
-
128
- - **Default**: Development/testing environment
129
- - **Staging**: Pre-production testing
130
- - **Production**: Live production environment
131
-
132
- Each environment can have its own configuration and secrets.
133
-
134
- ### Automated Deployment
135
-
136
- GitHub Actions workflows are included for automated deployment:
137
-
138
- - **Push to `main`**: Deploys to production
139
- - **Push to `staging`**: Deploys to staging
140
- - **Pull Requests**: Runs tests and builds
141
-
142
- Required GitHub Secrets:
143
- - `CLOUDFLARE_API_TOKEN`
144
- - `CLOUDFLARE_ACCOUNT_ID`
145
-
146
- For detailed deployment instructions, see [DEPLOYMENT.md](./DEPLOYMENT.md).
147
-
148
- ## API Endpoints
149
-
150
- ### Health Check
151
-
152
- ```http
153
- GET /
154
- GET /health
155
- ```
156
-
157
- ### Send Verification Code
158
-
159
- ```http
160
- POST /api/send
161
- Content-Type: application/json
162
- X-API-Key: your_api_key
163
-
164
- {
165
- "phoneNumber": "+1234567890",
166
- "code": "123456", // optional, auto-generated if not provided
167
- "blockVoip": true, // optional, default: false
168
- "senderId": "MyApp", // optional, default: "Verify"
169
- "messageTemplate": "Your code is: {code}", // optional
170
- "smsType": "Transactional" // optional, "Transactional" or "Promotional"
171
- }
172
- ```
173
-
174
- **Response:**
175
- ```json
176
- {
177
- "success": true,
178
- "message": "Verification code sent successfully",
179
- "messageId": "abc123def456",
180
- "code": "123456",
181
- "phoneNumber": "+1234567890",
182
- "expiresIn": 600
183
- }
184
- ```
185
-
186
- ### Verify Code
187
-
188
- ```http
189
- POST /api/verify
190
- Content-Type: application/json
191
- X-API-Key: your_api_key
192
-
193
- {
194
- "phoneNumber": "+1234567890",
195
- "code": "123456"
196
- }
197
- ```
198
-
199
- **Response:**
200
- ```json
201
- {
202
- "success": true,
203
- "message": "Code verified successfully",
204
- "verified": true
205
- }
206
- ```
207
-
208
- ### Send General SMS
209
-
210
- ```http
211
- POST /api/sms
212
- Content-Type: application/json
213
- X-API-Key: your_api_key
214
-
215
- {
216
- "phoneNumber": "+1234567890",
217
- "message": "Hello from your app!",
218
- "senderId": "MyApp",
219
- "smsType": "Transactional"
220
- }
221
- ```
222
-
223
- **Response:**
224
- ```json
225
- {
226
- "success": true,
227
- "message": "SMS sent successfully",
228
- "messageId": "abc123def456",
229
- "phoneNumber": "+1234567890"
230
- }
231
- ```
232
-
233
- ## API Documentation
234
-
235
- Visit `/docs` to see the interactive OpenAPI documentation.
236
-
237
- ## Authentication
238
-
239
- All API endpoints require authentication using an API key. Include the key in the request header:
240
-
241
- ```http
242
- X-API-Key: your_api_key
243
- ```
244
-
245
- Or as a Bearer token:
246
-
247
- ```http
248
- Authorization: Bearer your_api_key
249
- ```
250
-
251
- ## Configuration
252
-
253
- ### Environment Variables
254
-
255
- | Variable | Description | Default |
256
- |----------|-------------|---------|
257
- | `AWS_ACCESS_KEY_ID` | AWS Access Key ID | Required |
258
- | `AWS_SECRET_ACCESS_KEY` | AWS Secret Access Key | Required |
259
- | `AWS_REGION` | AWS Region | `us-east-1` |
260
- | `API_KEY` | API Key for authentication | Required |
261
- | `SMS_SENDER_ID` | Default SMS sender ID | `Verify` |
262
-
263
- ### Rate Limiting
264
-
265
- - **Window**: 15 minutes
266
- - **Max Requests**: 100 per IP
267
- - **Headers**: Standard rate limit headers included
268
-
269
- ### Phone Number Validation Options
270
-
271
- The API supports two methods for phone number validation and VoIP detection:
272
-
273
- #### 1. External API Method (Default)
274
- - Uses external phone lookup service for VoIP detection
275
- - Basic phone number formatting and validation
276
- - Requires internet access for VoIP checks
277
- - More accurate VoIP detection
278
-
279
- #### 2. libphonenumber-js Method
280
- - Uses Google's libphonenumber library for local analysis
281
- - Advanced phone number formatting and validation
282
- - No external API calls required
283
- - Heuristic-based VoIP detection
284
- - Smaller bundle size (145 kB vs 550 kB for full libphonenumber)
285
- - Better international number support
286
-
287
- #### Usage Examples
288
-
289
- ```javascript
290
- // Using libphonenumber-js for VoIP detection with full metadata
291
- const result = await verifyPhone({
292
- phoneNumber: '+1-800-555-0123',
293
- code: '123456',
294
- blockVoip: true,
295
- voipDetectionMethod: 'libphonenumber', // Use local analysis
296
- useLibPhoneNumber: true, // Use libphonenumber-js for formatting/validation
297
- metadataType: 'full' // Use full metadata (140KB) for better phone type detection
298
- });
299
-
300
- // Using libphonenumber-js for formatting only
301
- const result = await verifyPhone({
302
- phoneNumber: '555-123-4567', // US number without country code
303
- code: '789012',
304
- useLibPhoneNumber: true, // Use libphonenumber-js for formatting/validation
305
- blockVoip: false // Don't block VoIP numbers
306
- });
307
-
308
- // Traditional approach (external API)
309
- const result = await verifyPhone({
310
- phoneNumber: '+44 20 7946 0958', // UK number
311
- code: 'ABCDEF',
312
- blockVoip: true,
313
- voipDetectionMethod: 'api', // Use external API (default)
314
- useLibPhoneNumber: false // Use basic formatting/validation
315
- });
316
- ```
317
-
318
- #### VoIP Detection Methods
319
-
320
- **External API (`voipDetectionMethod: 'api'`):**
321
- - Checks carrier information from phone lookup service
322
- - Identifies Bandwidth, VoIP, and mobile line types
323
- - More accurate but requires external API calls
324
-
325
- **libphonenumber-js (`voipDetectionMethod: 'libphonenumber'`):**
326
- - Analyzes phone number patterns and structure
327
- - Identifies common VoIP area codes (800, 888, 877, etc.)
328
- - Detects non-geographic numbers
329
- - Recognizes patterns like repeated digits, sequential numbers
330
- - Heuristic-based approach for common VoIP characteristics
331
-
332
- #### Metadata Options
333
-
334
- **Minimal Metadata (`metadataType: 'minimal'` - Default, 75KB):**
335
- - Uses pattern-based heuristics for VoIP detection
336
- - Smaller bundle size
337
- - Works with all countries
338
- - Less accurate but faster
339
-
340
- **Full Metadata (`metadataType: 'full' - 140KB):**
341
- - Uses phone number type detection (MOBILE, FIXED_LINE, VOIP, etc.)
342
- - More accurate VoIP detection
343
- - Larger bundle size (65KB additional)
344
- - Matches Google's libphonenumber behavior
345
- - Phone number types: MOBILE, FIXED_LINE, VOIP, PREMIUM_RATE, TOLL_FREE, SHARED_COST
346
-
347
- ## Development
348
-
349
- ### Running Tests
350
-
351
- ```bash
352
- npm test
353
- npm run test:run
354
- npm run test:ui
355
- ```
356
-
357
- ### Local Development
358
-
359
- ```bash
360
- npm run dev
361
- ```
362
-
363
- ### Deployment
364
-
365
- ```bash
366
- # Deploy to production
367
- npm run deploy
368
-
369
- # Deploy to staging
370
- npm run deploy:staging
371
-
372
- # Deploy to specific environment
373
- npm run deploy:production
374
- ```
375
-
376
- ## Example Usage
377
-
378
- ### JavaScript/Node.js
379
-
380
- ```javascript
381
- // Send verification code
382
- const response = await fetch('https://your-api.workers.dev/api/send', {
383
- method: 'POST',
384
- headers: {
385
- 'Content-Type': 'application/json',
386
- 'X-API-Key': 'your_api_key'
387
- },
388
- body: JSON.stringify({
389
- phoneNumber: '+1234567890',
390
- blockVoip: true,
391
- senderId: 'MyApp'
392
- })
393
- });
394
-
395
- const result = await response.json();
396
- console.log(result);
397
- ```
398
-
399
- ### cURL
400
-
401
- ```bash
402
- # Send verification code
403
- curl -X POST https://your-api.workers.dev/api/send \
404
- -H "Content-Type: application/json" \
405
- -H "X-API-Key: your_api_key" \
406
- -d '{
407
- "phoneNumber": "+1234567890",
408
- "blockVoip": true,
409
- "senderId": "MyApp"
410
- }'
411
-
412
- # Verify code
413
- curl -X POST https://your-api.workers.dev/api/verify \
414
- -H "Content-Type: application/json" \
415
- -H "X-API-Key: your_api_key" \
416
- -d '{
417
- "phoneNumber": "+1234567890",
418
- "code": "123456"
419
- }'
420
- ```
421
-
422
- ## Error Handling
423
-
424
- The API returns consistent error responses:
425
-
426
- ```json
427
- {
428
- "success": false,
429
- "error": "Error message",
430
- "details": "Additional error details"
431
- }
432
- ```
433
-
434
- Common HTTP status codes:
435
- - `200`: Success
436
- - `400`: Bad request (invalid input)
437
- - `401`: Unauthorized (invalid API key)
438
- - `429`: Too many requests (rate limited)
439
- - `500`: Internal server error
440
-
441
- ## Security Features
442
-
443
- - ✅ API key authentication
444
- - ✅ Rate limiting
445
- - ✅ CORS protection
446
- - ✅ Secure headers
447
- - ✅ Input validation
448
- - ✅ Error sanitization
449
- - ✅ VoIP number blocking (optional)
450
-
451
- ## Architecture
452
-
453
- ```
454
- ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
455
- │ Client App │───▶│ Hono Server │───▶│ AWS SNS │
456
- │ │ │ │ │ │
457
- │ - Web App │ │ - Rate Limiting │ │ - SMS Delivery │
458
- │ - Mobile App │ │ - Auth │ │ - Message ID │
459
- │ - API Client │ │ - Validation │ │ - Error Handling│
460
- └─────────────────┘ └─────────────────┘ └─────────────────┘
461
- ```
462
-
463
- ## Roadmap: Identity Verification
464
-
465
- Phone verification proves control of a number. The next tier proves the person
466
- behind that number is real — and turns that proof into something businesses pay
467
- for.
468
-
469
- ### Planned integrations
470
-
471
- - **Persona API** — document and selfie identity verification. Entry plan is
472
- **$250/month, including 166 verifications** (~$1.50 each); volume past the
473
- included allowance is billed per verification.
474
- - **Auto sign-in by phone** — once a registered user's number is verified and on
475
- file, authenticate them from the phone itself instead of re-sending a code on
476
- every login.
477
- - **Address history over legal ID** — a chain of past addresses is a stronger
478
- identity signal than a photo of a government ID, which can be AI-generated or
479
- reused across accounts. Treat document capture as corroboration, not proof.
480
- - **Liveness and face check** — confirm a live human is present at capture time,
481
- rather than a printed photo, a replayed video, or a generated face.
482
-
483
- ### Product opportunities
484
-
485
- - **Verification as a service** — sell corporations the ability to confirm their
486
- customers are real people, with this stack as the verification backend.
487
- - **Verified demographics** — verified age, location, and demographic attributes
488
- make high-quality ad targeting inventory, subject to user consent and
489
- applicable privacy law.
490
-
491
- ### References
492
-
493
- - [NIST FRVT 1:1 leaderboard](https://pages.nist.gov/frvt/html/frvt11.html) — accuracy rankings for face recognition algorithms
494
- - [Faceplugin FaceRecognition-Android](https://github.com/Faceplugin-ltd/FaceRecognition-Android) — on-device face recognition with liveness check
495
- - [Doubango FaceLivenessDetection-SDK](https://github.com/DoubangoTelecom/FaceLivenessDetection-SDK) — passive face liveness / anti-spoofing
496
-
497
- ## Contributing
498
-
499
- 1. Fork the repository
500
- 2. Create a feature branch
501
- 3. Make your changes
502
- 4. Add tests
503
- 5. Submit a pull request
504
-
505
- ## License
506
-
507
- MIT License - see LICENSE file for details.
508
-
509
- ---
510
-
511
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
512
-
513
- Please star this repo for updates! 🌟
1
+ <!-- template-git-repo:badges:start -->
2
+ <p align="center">
3
+ <a href="https://starterdocs.vtempest.workers.dev/docs/packages/verify-phone-sms"><img src="https://img.shields.io/badge/Docs-blue?logo=ReadTheDocs&logoColor=white" alt="Documentation" /></a>
4
+ <a href="https://stackblitz.com/github/OpenSourceAGI/dev-tools-starter-agent/tree/master/packages/verify-phone-sms"><img height="20px" src="https://developer.stackblitz.com/img/open_in_stackblitz.svg" alt="Open in StackBlitz" /></a>
5
+ <br />
6
+ <a href="https://www.npmjs.com/package/verify-phone-sms"><img src="https://img.shields.io/npm/dm/verify-phone-sms.svg" alt="NPM Monthly Downloads" /></a>
7
+ <a href="https://www.npmjs.com/package/verify-phone-sms"><img src="https://img.shields.io/npm/v/verify-phone-sms.svg" alt="npm version" /></a>
8
+ <a href="https://www.npmjs.com/package/verify-phone-sms"><img src="https://img.shields.io/npm/dt/verify-phone-sms.svg" alt="NPM Total Downloads" /></a>
9
+ <a href="https://www.npmjs.com/package/verify-phone-sms"><img src="https://img.shields.io/npm/types/verify-phone-sms" alt="TypeScript types" /></a>
10
+ <a href="https://packagephobia.com/result?p=verify-phone-sms"><img src="https://packagephobia.com/badge?p=verify-phone-sms" alt="Install size" /></a>
11
+ <a href="https://app.codecov.io/gh/OpenSourceAGI/dev-tools-starter-agent/flags"><img src="https://img.shields.io/codecov/c/github/OpenSourceAGI/dev-tools-starter-agent?flag=verify-phone-sms&label=verify-phone-sms%20coverage&logo=codecov&logoColor=white" alt="Coverage" /></a>
12
+ </p>
13
+ <!-- template-git-repo:badges:end -->
14
+
15
+ <!-- skills:install:start -->
16
+ **🤖 Agent skill** — `npx skills@latest add https://github.com/OpenSourceAGI/dev-tools-starter-agent --skill verify-phone-sms` ([what it covers](../../skills/verify-phone-sms/SKILL.md))
17
+ <!-- skills:install:end -->
18
+
19
+ # SMS Verification API Server
20
+
21
+ A complete Hono-based server for SMS verification using AWS SNS. Built for Cloudflare Workers with comprehensive API documentation and security features.
22
+
23
+ ## Features
24
+
25
+ - ✅ **SMS Verification**: Send verification codes via AWS SNS
26
+ - ✅ **VoIP Blocking**: Optional blocking of VoIP numbers
27
+ - ✅ **API Authentication**: Secure API key-based authentication
28
+ - ✅ **Rate Limiting**: Built-in rate limiting protection
29
+ - ✅ **OpenAPI Documentation**: Auto-generated API documentation
30
+ - ✅ **CORS Support**: Cross-origin resource sharing enabled
31
+ - ✅ **Security Headers**: Secure headers middleware
32
+ - ✅ **Error Handling**: Comprehensive error handling
33
+ - ✅ **Health Checks**: Built-in health monitoring
34
+ - ✅ **General SMS**: Send custom SMS messages
35
+
36
+
37
+
38
+ ## Quick Start
39
+
40
+ ### 1. Install
41
+
42
+ ```bash
43
+ npm install verify-phone-sms # use verifyPhone() from your own backend
44
+ ```
45
+
46
+ Or clone the repo and install its dependencies to run the server itself:
47
+
48
+ ```bash
49
+ npm install
50
+ ```
51
+
52
+ ### 2. Set Environment Variables
53
+
54
+ Create a `.env` file or set environment variables:
55
+
56
+ ```bash
57
+ # AWS Credentials
58
+ AWS_ACCESS_KEY_ID=your_aws_access_key
59
+ AWS_SECRET_ACCESS_KEY=your_aws_secret_key
60
+ AWS_REGION=us-east-1
61
+
62
+ # API Configuration
63
+ API_KEY=sms_1234567890abcdef1234567890abcdef
64
+ SMS_SENDER_ID=Verify
65
+ ```
66
+
67
+ ### 3. Run Development Server
68
+
69
+ ```bash
70
+ npm run dev
71
+ ```
72
+
73
+ The server will be available at `http://localhost:8787`
74
+
75
+ ### 4. Deploy to Cloudflare Workers
76
+
77
+ ```bash
78
+ # Deploy API only
79
+ npm run deploy
80
+
81
+ # Deploy docs only
82
+ npm run build:docs
83
+ npm run deploy:docs
84
+
85
+ # Deploy both API and docs
86
+ npm run deploy:all
87
+
88
+ # Deploy to specific environments
89
+ npm run deploy:staging
90
+ npm run deploy:production
91
+ npm run deploy:all:staging
92
+ npm run deploy:all:production
93
+ ```
94
+
95
+ ### 5. Quick Deployment Script
96
+
97
+ ```bash
98
+ # Deploy everything to default environment
99
+ ./scripts/deploy.sh
100
+
101
+ # Deploy to staging
102
+ ./scripts/deploy.sh staging
103
+
104
+ # Deploy to production
105
+ ./scripts/deploy.sh production
106
+
107
+ # Deploy only API
108
+ ./scripts/deploy.sh default api
109
+
110
+ # Deploy only docs
111
+ ./scripts/deploy.sh default docs
112
+ ```
113
+
114
+ ## Deployment
115
+
116
+ ### Prerequisites
117
+
118
+ 1. **Install Wrangler CLI**:
119
+ ```bash
120
+ npm install -g wrangler
121
+ ```
122
+
123
+ 2. **Login to Cloudflare**:
124
+ ```bash
125
+ wrangler login
126
+ ```
127
+
128
+ 3. **Set Secrets**:
129
+ ```bash
130
+ wrangler secret put AWS_ACCESS_KEY_ID
131
+ wrangler secret put AWS_SECRET_ACCESS_KEY
132
+ wrangler secret put API_KEY
133
+ ```
134
+
135
+ ### Environment Configuration
136
+
137
+ The project supports multiple deployment environments:
138
+
139
+ - **Default**: Development/testing environment
140
+ - **Staging**: Pre-production testing
141
+ - **Production**: Live production environment
142
+
143
+ Each environment can have its own configuration and secrets.
144
+
145
+ ### Automated Deployment
146
+
147
+ GitHub Actions workflows are included for automated deployment:
148
+
149
+ - **Push to `main`**: Deploys to production
150
+ - **Push to `staging`**: Deploys to staging
151
+ - **Pull Requests**: Runs tests and builds
152
+
153
+ Required GitHub Secrets:
154
+ - `CLOUDFLARE_API_TOKEN`
155
+ - `CLOUDFLARE_ACCOUNT_ID`
156
+
157
+ For detailed deployment instructions, see [DEPLOYMENT.md](./DEPLOYMENT.md).
158
+
159
+ ## API Endpoints
160
+
161
+ ### Health Check
162
+
163
+ ```http
164
+ GET /
165
+ GET /health
166
+ ```
167
+
168
+ ### Send Verification Code
169
+
170
+ ```http
171
+ POST /api/send
172
+ Content-Type: application/json
173
+ X-API-Key: your_api_key
174
+
175
+ {
176
+ "phoneNumber": "+1234567890",
177
+ "code": "123456", // optional, auto-generated if not provided
178
+ "blockVoip": true, // optional, default: false
179
+ "senderId": "MyApp", // optional, default: "Verify"
180
+ "messageTemplate": "Your code is: {code}", // optional
181
+ "smsType": "Transactional" // optional, "Transactional" or "Promotional"
182
+ }
183
+ ```
184
+
185
+ **Response:**
186
+ ```json
187
+ {
188
+ "success": true,
189
+ "message": "Verification code sent successfully",
190
+ "messageId": "abc123def456",
191
+ "code": "123456",
192
+ "phoneNumber": "+1234567890",
193
+ "expiresIn": 600
194
+ }
195
+ ```
196
+
197
+ ### Verify Code
198
+
199
+ ```http
200
+ POST /api/verify
201
+ Content-Type: application/json
202
+ X-API-Key: your_api_key
203
+
204
+ {
205
+ "phoneNumber": "+1234567890",
206
+ "code": "123456"
207
+ }
208
+ ```
209
+
210
+ **Response:**
211
+ ```json
212
+ {
213
+ "success": true,
214
+ "message": "Code verified successfully",
215
+ "verified": true
216
+ }
217
+ ```
218
+
219
+ ### Send General SMS
220
+
221
+ ```http
222
+ POST /api/sms
223
+ Content-Type: application/json
224
+ X-API-Key: your_api_key
225
+
226
+ {
227
+ "phoneNumber": "+1234567890",
228
+ "message": "Hello from your app!",
229
+ "senderId": "MyApp",
230
+ "smsType": "Transactional"
231
+ }
232
+ ```
233
+
234
+ **Response:**
235
+ ```json
236
+ {
237
+ "success": true,
238
+ "message": "SMS sent successfully",
239
+ "messageId": "abc123def456",
240
+ "phoneNumber": "+1234567890"
241
+ }
242
+ ```
243
+
244
+ ## API Documentation
245
+
246
+ Visit `/docs` to see the interactive OpenAPI documentation.
247
+
248
+ ## Authentication
249
+
250
+ All API endpoints require authentication using an API key. Include the key in the request header:
251
+
252
+ ```http
253
+ X-API-Key: your_api_key
254
+ ```
255
+
256
+ Or as a Bearer token:
257
+
258
+ ```http
259
+ Authorization: Bearer your_api_key
260
+ ```
261
+
262
+ ## Configuration
263
+
264
+ ### Environment Variables
265
+
266
+ | Variable | Description | Default |
267
+ |----------|-------------|---------|
268
+ | `AWS_ACCESS_KEY_ID` | AWS Access Key ID | Required |
269
+ | `AWS_SECRET_ACCESS_KEY` | AWS Secret Access Key | Required |
270
+ | `AWS_REGION` | AWS Region | `us-east-1` |
271
+ | `API_KEY` | API Key for authentication | Required |
272
+ | `SMS_SENDER_ID` | Default SMS sender ID | `Verify` |
273
+
274
+ ### Rate Limiting
275
+
276
+ - **Window**: 15 minutes
277
+ - **Max Requests**: 100 per IP
278
+ - **Headers**: Standard rate limit headers included
279
+
280
+ ### Phone Number Validation Options
281
+
282
+ The API supports two methods for phone number validation and VoIP detection:
283
+
284
+ #### 1. External API Method (Default)
285
+ - Uses external phone lookup service for VoIP detection
286
+ - Basic phone number formatting and validation
287
+ - Requires internet access for VoIP checks
288
+ - More accurate VoIP detection
289
+
290
+ #### 2. libphonenumber-js Method
291
+ - Uses Google's libphonenumber library for local analysis
292
+ - Advanced phone number formatting and validation
293
+ - No external API calls required
294
+ - Heuristic-based VoIP detection
295
+ - Smaller bundle size (145 kB vs 550 kB for full libphonenumber)
296
+ - Better international number support
297
+
298
+ #### Usage Examples
299
+
300
+ ```javascript
301
+ // Using libphonenumber-js for VoIP detection with full metadata
302
+ const result = await verifyPhone({
303
+ phoneNumber: '+1-800-555-0123',
304
+ code: '123456',
305
+ blockVoip: true,
306
+ voipDetectionMethod: 'libphonenumber', // Use local analysis
307
+ useLibPhoneNumber: true, // Use libphonenumber-js for formatting/validation
308
+ metadataType: 'full' // Use full metadata (140KB) for better phone type detection
309
+ });
310
+
311
+ // Using libphonenumber-js for formatting only
312
+ const result = await verifyPhone({
313
+ phoneNumber: '555-123-4567', // US number without country code
314
+ code: '789012',
315
+ useLibPhoneNumber: true, // Use libphonenumber-js for formatting/validation
316
+ blockVoip: false // Don't block VoIP numbers
317
+ });
318
+
319
+ // Traditional approach (external API)
320
+ const result = await verifyPhone({
321
+ phoneNumber: '+44 20 7946 0958', // UK number
322
+ code: 'ABCDEF',
323
+ blockVoip: true,
324
+ voipDetectionMethod: 'api', // Use external API (default)
325
+ useLibPhoneNumber: false // Use basic formatting/validation
326
+ });
327
+ ```
328
+
329
+ #### VoIP Detection Methods
330
+
331
+ **External API (`voipDetectionMethod: 'api'`):**
332
+ - Checks carrier information from phone lookup service
333
+ - Identifies Bandwidth, VoIP, and mobile line types
334
+ - More accurate but requires external API calls
335
+
336
+ **libphonenumber-js (`voipDetectionMethod: 'libphonenumber'`):**
337
+ - Analyzes phone number patterns and structure
338
+ - Identifies common VoIP area codes (800, 888, 877, etc.)
339
+ - Detects non-geographic numbers
340
+ - Recognizes patterns like repeated digits, sequential numbers
341
+ - Heuristic-based approach for common VoIP characteristics
342
+
343
+ #### Metadata Options
344
+
345
+ **Minimal Metadata (`metadataType: 'minimal'` - Default, 75KB):**
346
+ - Uses pattern-based heuristics for VoIP detection
347
+ - Smaller bundle size
348
+ - Works with all countries
349
+ - Less accurate but faster
350
+
351
+ **Full Metadata (`metadataType: 'full' - 140KB):**
352
+ - Uses phone number type detection (MOBILE, FIXED_LINE, VOIP, etc.)
353
+ - More accurate VoIP detection
354
+ - Larger bundle size (65KB additional)
355
+ - Matches Google's libphonenumber behavior
356
+ - Phone number types: MOBILE, FIXED_LINE, VOIP, PREMIUM_RATE, TOLL_FREE, SHARED_COST
357
+
358
+ ## Development
359
+
360
+ ### Running Tests
361
+
362
+ ```bash
363
+ npm test
364
+ npm run test:run
365
+ npm run test:ui
366
+ ```
367
+
368
+ ### Local Development
369
+
370
+ ```bash
371
+ npm run dev
372
+ ```
373
+
374
+ ### Deployment
375
+
376
+ ```bash
377
+ # Deploy to production
378
+ npm run deploy
379
+
380
+ # Deploy to staging
381
+ npm run deploy:staging
382
+
383
+ # Deploy to specific environment
384
+ npm run deploy:production
385
+ ```
386
+
387
+ ## Example Usage
388
+
389
+ ### JavaScript/Node.js
390
+
391
+ ```javascript
392
+ // Send verification code
393
+ const response = await fetch('https://your-api.workers.dev/api/send', {
394
+ method: 'POST',
395
+ headers: {
396
+ 'Content-Type': 'application/json',
397
+ 'X-API-Key': 'your_api_key'
398
+ },
399
+ body: JSON.stringify({
400
+ phoneNumber: '+1234567890',
401
+ blockVoip: true,
402
+ senderId: 'MyApp'
403
+ })
404
+ });
405
+
406
+ const result = await response.json();
407
+ console.log(result);
408
+ ```
409
+
410
+ ### cURL
411
+
412
+ ```bash
413
+ # Send verification code
414
+ curl -X POST https://your-api.workers.dev/api/send \
415
+ -H "Content-Type: application/json" \
416
+ -H "X-API-Key: your_api_key" \
417
+ -d '{
418
+ "phoneNumber": "+1234567890",
419
+ "blockVoip": true,
420
+ "senderId": "MyApp"
421
+ }'
422
+
423
+ # Verify code
424
+ curl -X POST https://your-api.workers.dev/api/verify \
425
+ -H "Content-Type: application/json" \
426
+ -H "X-API-Key: your_api_key" \
427
+ -d '{
428
+ "phoneNumber": "+1234567890",
429
+ "code": "123456"
430
+ }'
431
+ ```
432
+
433
+ ## Error Handling
434
+
435
+ The API returns consistent error responses:
436
+
437
+ ```json
438
+ {
439
+ "success": false,
440
+ "error": "Error message",
441
+ "details": "Additional error details"
442
+ }
443
+ ```
444
+
445
+ Common HTTP status codes:
446
+ - `200`: Success
447
+ - `400`: Bad request (invalid input)
448
+ - `401`: Unauthorized (invalid API key)
449
+ - `429`: Too many requests (rate limited)
450
+ - `500`: Internal server error
451
+
452
+ ## Security Features
453
+
454
+ - ✅ API key authentication
455
+ - ✅ Rate limiting
456
+ - ✅ CORS protection
457
+ - ✅ Secure headers
458
+ - ✅ Input validation
459
+ - ✅ Error sanitization
460
+ - ✅ VoIP number blocking (optional)
461
+
462
+ ## Architecture
463
+
464
+ ```
465
+ ┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
466
+ │ Client App │───▶│ Hono Server │───▶│ AWS SNS │
467
+ │ │ │ │ │ │
468
+ │ - Web App │ │ - Rate Limiting │ │ - SMS Delivery │
469
+ │ - Mobile App │ │ - Auth │ │ - Message ID │
470
+ │ - API Client │ │ - Validation │ │ - Error Handling│
471
+ └─────────────────┘ └─────────────────┘ └─────────────────┘
472
+ ```
473
+
474
+ ## Roadmap: Identity Verification
475
+
476
+ Phone verification proves control of a number. The next tier proves the person
477
+ behind that number is real — and turns that proof into something businesses pay
478
+ for.
479
+
480
+ ### Planned integrations
481
+
482
+ - **Persona API** — document and selfie identity verification. Entry plan is
483
+ **$250/month, including 166 verifications** (~$1.50 each); volume past the
484
+ included allowance is billed per verification.
485
+ - **Auto sign-in by phone** — once a registered user's number is verified and on
486
+ file, authenticate them from the phone itself instead of re-sending a code on
487
+ every login.
488
+ - **Address history over legal ID** — a chain of past addresses is a stronger
489
+ identity signal than a photo of a government ID, which can be AI-generated or
490
+ reused across accounts. Treat document capture as corroboration, not proof.
491
+ - **Liveness and face check** — confirm a live human is present at capture time,
492
+ rather than a printed photo, a replayed video, or a generated face.
493
+
494
+ ### Product opportunities
495
+
496
+ - **Verification as a service** — sell corporations the ability to confirm their
497
+ customers are real people, with this stack as the verification backend.
498
+ - **Verified demographics** — verified age, location, and demographic attributes
499
+ make high-quality ad targeting inventory, subject to user consent and
500
+ applicable privacy law.
501
+
502
+ ### References
503
+
504
+ - [NIST FRVT 1:1 leaderboard](https://pages.nist.gov/frvt/html/frvt11.html) — accuracy rankings for face recognition algorithms
505
+ - [Faceplugin FaceRecognition-Android](https://github.com/Faceplugin-ltd/FaceRecognition-Android) — on-device face recognition with liveness check
506
+ - [Doubango FaceLivenessDetection-SDK](https://github.com/DoubangoTelecom/FaceLivenessDetection-SDK) — passive face liveness / anti-spoofing
507
+
508
+ ## Contributing
509
+
510
+ 1. Fork the repository
511
+ 2. Create a feature branch
512
+ 3. Make your changes
513
+ 4. Add tests
514
+ 5. Submit a pull request
515
+
516
+ ## License
517
+
518
+ MIT License - see LICENSE file for details.
519
+
520
+ ---
521
+
522
+ [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request)
523
+
524
+ Please star this repo for updates! 🌟
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "verify-phone-sms",
3
- "version": "0.9.60",
3
+ "version": "0.9.61",
4
4
  "description": "SMS Phone Verification API using AWS SNS HTTP API with Hono server on Cloudflare Workers",
5
5
  "main": "src/verify-phone.ts",
6
6
  "type": "module",