sms-verification-api 0.9.1

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 (50) hide show
  1. package/.env.example +20 -0
  2. package/DEPLOYMENT.md +151 -0
  3. package/README.md +475 -0
  4. package/docs/app/(home)/layout.tsx +7 -0
  5. package/docs/app/(home)/page.tsx +38 -0
  6. package/docs/app/docs/[[...slug]]/page.tsx +59 -0
  7. package/docs/app/docs/layout.tsx +12 -0
  8. package/docs/app/docs-og/[...slug]/route.ts +24 -0
  9. package/docs/app/globals.css +587 -0
  10. package/docs/app/layout.config.tsx +13 -0
  11. package/docs/app/layout.tsx +27 -0
  12. package/docs/app/logo.tsx +35 -0
  13. package/docs/content/docs/API_AUTHENTICATION.md +91 -0
  14. package/docs/content/docs/DEPLOYMENT.md +181 -0
  15. package/docs/content/docs/api/post.mdx +35 -0
  16. package/docs/content/docs/api/verify.mdx +34 -0
  17. package/docs/content/docs/meta.json +8 -0
  18. package/docs/content/docs/verify-legal-name.md +339 -0
  19. package/docs/lib/source.ts +14 -0
  20. package/docs/mdx-components.tsx +12 -0
  21. package/docs/next.config.mjs +51 -0
  22. package/docs/openapi.json +329 -0
  23. package/docs/package.json +37 -0
  24. package/docs/postcss.config.mjs +5 -0
  25. package/docs/scripts/generate-docs.mjs +23 -0
  26. package/docs/source.config.ts +5 -0
  27. package/docs/tsconfig.json +29 -0
  28. package/docs/worker.js +35 -0
  29. package/docs/wrangler.toml +26 -0
  30. package/examples/client.js +119 -0
  31. package/examples/demo.html +325 -0
  32. package/examples/libphonenumber-example.js +120 -0
  33. package/openapi.json +329 -0
  34. package/package.json +71 -0
  35. package/scripts/deploy.sh +63 -0
  36. package/src/identity-verification-server.ts +553 -0
  37. package/src/index.js +8 -0
  38. package/src/sns.js +236 -0
  39. package/src/verify-phone-server.js +448 -0
  40. package/src/verify-phone.ts +551 -0
  41. package/test/api.test.js +201 -0
  42. package/test/integration.test.js +152 -0
  43. package/test/metadata-test.js +73 -0
  44. package/test/server.test.js +143 -0
  45. package/test/setup.js +32 -0
  46. package/test/utils.test.js +186 -0
  47. package/test/verify.test.js +23 -0
  48. package/test/voip.test.js +112 -0
  49. package/vitest.config.js +10 -0
  50. package/wrangler.toml +27 -0
package/openapi.json ADDED
@@ -0,0 +1,329 @@
1
+ {
2
+ "openapi": "3.0.0",
3
+ "info": {
4
+ "version": "1.0.0",
5
+ "title": "SMS Verification API",
6
+ "description": "A comprehensive SMS verification API using AWS SNS HTTP API with Hono server on Cloudflare Workers. **Authentication Required**: All endpoints except `/health`, `/docs`, and `/openapi.json` require API key authentication.",
7
+ "contact": { "name": "API Support", "email": "support@example.com" },
8
+ "license": { "name": "MIT", "url": "https://opensource.org/licenses/MIT" }
9
+ },
10
+ "servers": [
11
+ {
12
+ "url": "https://sms-verification-api.your-subdomain.workers.dev",
13
+ "description": "Production server"
14
+ },
15
+ {
16
+ "url": "https://sms-verification-api-staging.your-subdomain.workers.dev",
17
+ "description": "Staging server"
18
+ }
19
+ ],
20
+ "components": { "schemas": {}, "parameters": {} },
21
+ "security": [{ "ApiKeyAuth": [] }, { "BearerAuth": [] }],
22
+ "paths": {
23
+ "/health": {
24
+ "get": {
25
+ "tags": ["health"],
26
+ "summary": "Health check",
27
+ "description": "Returns the health status of the API server",
28
+ "responses": {
29
+ "200": {
30
+ "description": "Health check successful",
31
+ "content": {
32
+ "application/json": {
33
+ "schema": {
34
+ "type": "object",
35
+ "properties": {
36
+ "status": { "type": "string", "example": "ok" },
37
+ "timestamp": {
38
+ "type": "string",
39
+ "example": "2024-01-01T00:00:00.000Z"
40
+ },
41
+ "server": {
42
+ "type": "string",
43
+ "example": "Hono on Cloudflare Workers"
44
+ }
45
+ },
46
+ "required": ["status", "timestamp", "server"]
47
+ }
48
+ }
49
+ }
50
+ }
51
+ }
52
+ }
53
+ },
54
+ "/api/send-verification": {
55
+ "post": {
56
+ "tags": ["verification"],
57
+ "summary": "Send SMS verification code",
58
+ "description": "Sends a 6-digit verification code to the specified phone number via SMS. Optionally accepts a custom code.",
59
+ "security": [{ "ApiKeyAuth": [] }, { "BearerAuth": [] }],
60
+ "requestBody": {
61
+ "content": {
62
+ "application/json": {
63
+ "schema": {
64
+ "type": "object",
65
+ "properties": {
66
+ "phoneNumber": {
67
+ "type": "string",
68
+ "pattern": "^\\+[1-9]\\d{1,14}$",
69
+ "description": "Phone number in E.164 format",
70
+ "example": "+1234567890"
71
+ },
72
+ "code": {
73
+ "type": "string",
74
+ "minLength": 6,
75
+ "maxLength": 6,
76
+ "pattern": "^\\d{6}$",
77
+ "description": "Optional custom 6-digit verification code. If not provided, a random code will be generated.",
78
+ "example": "123456"
79
+ }
80
+ },
81
+ "required": ["phoneNumber"]
82
+ }
83
+ }
84
+ }
85
+ },
86
+ "responses": {
87
+ "200": {
88
+ "description": "Verification code sent successfully",
89
+ "content": {
90
+ "application/json": {
91
+ "schema": {
92
+ "type": "object",
93
+ "properties": {
94
+ "success": { "type": "boolean", "example": true },
95
+ "message": {
96
+ "type": "string",
97
+ "example": "Verification code sent successfully"
98
+ },
99
+ "messageId": {
100
+ "type": "string",
101
+ "example": "aws-message-id-123"
102
+ },
103
+ "expiresIn": {
104
+ "type": "number",
105
+ "description": "Expiration time in seconds",
106
+ "example": 600
107
+ }
108
+ },
109
+ "required": ["success", "message", "messageId", "expiresIn"]
110
+ }
111
+ }
112
+ }
113
+ },
114
+ "400": {
115
+ "description": "Bad request - invalid phone number or other validation error",
116
+ "content": {
117
+ "application/json": {
118
+ "schema": {
119
+ "type": "object",
120
+ "properties": {
121
+ "error": {
122
+ "type": "string",
123
+ "example": "Validation error"
124
+ },
125
+ "details": {
126
+ "type": "string",
127
+ "example": "Additional error details"
128
+ }
129
+ },
130
+ "required": ["error"]
131
+ }
132
+ }
133
+ }
134
+ },
135
+ "429": {
136
+ "description": "Too many requests - rate limited",
137
+ "content": {
138
+ "application/json": {
139
+ "schema": {
140
+ "type": "object",
141
+ "properties": {
142
+ "error": {
143
+ "type": "string",
144
+ "example": "Please wait before requesting another code"
145
+ },
146
+ "retryAfter": {
147
+ "type": "number",
148
+ "description": "Seconds to wait before retry",
149
+ "example": 30
150
+ }
151
+ },
152
+ "required": ["error", "retryAfter"]
153
+ }
154
+ }
155
+ }
156
+ },
157
+ "500": {
158
+ "description": "Internal server error",
159
+ "content": {
160
+ "application/json": {
161
+ "schema": {
162
+ "type": "object",
163
+ "properties": {
164
+ "error": {
165
+ "type": "string",
166
+ "example": "Validation error"
167
+ },
168
+ "details": {
169
+ "type": "string",
170
+ "example": "Additional error details"
171
+ }
172
+ },
173
+ "required": ["error"]
174
+ }
175
+ }
176
+ }
177
+ }
178
+ }
179
+ }
180
+ },
181
+ "/api/verify-code": {
182
+ "post": {
183
+ "tags": ["verification"],
184
+ "summary": "Verify SMS code",
185
+ "description": "Verifies the submitted code against the sent verification code",
186
+ "security": [{ "ApiKeyAuth": [] }, { "BearerAuth": [] }],
187
+ "requestBody": {
188
+ "content": {
189
+ "application/json": {
190
+ "schema": {
191
+ "type": "object",
192
+ "properties": {
193
+ "phoneNumber": {
194
+ "type": "string",
195
+ "pattern": "^\\+[1-9]\\d{1,14}$",
196
+ "description": "Phone number in E.164 format",
197
+ "example": "+1234567890"
198
+ },
199
+ "code": {
200
+ "type": "string",
201
+ "minLength": 6,
202
+ "maxLength": 6,
203
+ "pattern": "^\\d{6}$",
204
+ "description": "6-digit verification code",
205
+ "example": "123456"
206
+ }
207
+ },
208
+ "required": ["phoneNumber", "code"]
209
+ }
210
+ }
211
+ }
212
+ },
213
+ "responses": {
214
+ "200": {
215
+ "description": "Phone number verified successfully",
216
+ "content": {
217
+ "application/json": {
218
+ "schema": {
219
+ "type": "object",
220
+ "properties": {
221
+ "success": { "type": "boolean", "example": true },
222
+ "message": {
223
+ "type": "string",
224
+ "example": "Phone number verified successfully"
225
+ },
226
+ "verificationToken": {
227
+ "type": "string",
228
+ "example": "unique-verification-token"
229
+ },
230
+ "phoneNumber": {
231
+ "type": "string",
232
+ "pattern": "^\\+[1-9]\\d{1,14}$",
233
+ "description": "Phone number in E.164 format",
234
+ "example": "+1234567890"
235
+ }
236
+ },
237
+ "required": [
238
+ "success",
239
+ "message",
240
+ "verificationToken",
241
+ "phoneNumber"
242
+ ]
243
+ }
244
+ }
245
+ }
246
+ },
247
+ "400": {
248
+ "description": "Bad request - invalid code or expired",
249
+ "content": {
250
+ "application/json": {
251
+ "schema": {
252
+ "anyOf": [
253
+ {
254
+ "type": "object",
255
+ "properties": {
256
+ "error": {
257
+ "type": "string",
258
+ "example": "Validation error"
259
+ },
260
+ "details": {
261
+ "type": "string",
262
+ "example": "Additional error details"
263
+ }
264
+ },
265
+ "required": ["error"]
266
+ },
267
+ {
268
+ "type": "object",
269
+ "properties": {
270
+ "error": {
271
+ "type": "string",
272
+ "example": "Invalid verification code"
273
+ },
274
+ "attemptsRemaining": { "type": "number", "example": 3 }
275
+ },
276
+ "required": ["error", "attemptsRemaining"]
277
+ }
278
+ ]
279
+ }
280
+ }
281
+ }
282
+ },
283
+ "429": {
284
+ "description": "Too many verification attempts",
285
+ "content": {
286
+ "application/json": {
287
+ "schema": {
288
+ "type": "object",
289
+ "properties": {
290
+ "error": {
291
+ "type": "string",
292
+ "example": "Validation error"
293
+ },
294
+ "details": {
295
+ "type": "string",
296
+ "example": "Additional error details"
297
+ }
298
+ },
299
+ "required": ["error"]
300
+ }
301
+ }
302
+ }
303
+ },
304
+ "500": {
305
+ "description": "Internal server error",
306
+ "content": {
307
+ "application/json": {
308
+ "schema": {
309
+ "type": "object",
310
+ "properties": {
311
+ "error": {
312
+ "type": "string",
313
+ "example": "Validation error"
314
+ },
315
+ "details": {
316
+ "type": "string",
317
+ "example": "Additional error details"
318
+ }
319
+ },
320
+ "required": ["error"]
321
+ }
322
+ }
323
+ }
324
+ }
325
+ }
326
+ }
327
+ }
328
+ }
329
+ }
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "sms-verification-api",
3
+ "version": "0.9.1",
4
+ "description": "SMS Phone Verification API using AWS SNS HTTP API with Hono server on Cloudflare Workers",
5
+ "main": "src/verify-phone.js",
6
+ "type": "module",
7
+ "types": "./src/verify-phone.d.ts",
8
+ "module": "./src/verify-phone.js",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./src/verify-phone.d.ts",
12
+ "import": "./src/verify-phone.js",
13
+ "require": "./src/verify-phone.js"
14
+ }
15
+ },
16
+ "scripts": {
17
+ "dev": "wrangler dev",
18
+ "ship": "bun run standard-version --release-as patch; bun publish",
19
+ "deploy": "wrangler deploy",
20
+ "deploy:staging": "wrangler deploy --env staging",
21
+ "deploy:production": "wrangler deploy --env production",
22
+ "deploy:docs": "cd docs && bun run build && wrangler deploy",
23
+ "deploy:docs:staging": "cd docs && bun run build && wrangler deploy --env staging",
24
+ "deploy:docs:production": "cd docs && bun run build && wrangler deploy --env production",
25
+ "deploy:all": "bun run deploy && bun run deploy:docs",
26
+ "deploy:all:staging": "bun run deploy:staging && bun run deploy:docs:staging",
27
+ "deploy:all:production": "bun run deploy:production && bun run deploy:docs:production",
28
+ "build": "echo 'No build step needed for Workers'",
29
+ "build:docs": "cd docs && bun run build",
30
+ "test": "vitest",
31
+ "test:run": "vitest run",
32
+ "test:ui": "vitest --ui",
33
+ "lint": "eslint .",
34
+ "format": "prettier --write ."
35
+ },
36
+ "keywords": [
37
+ "sms",
38
+ "verification",
39
+ "aws",
40
+ "sns",
41
+ "phone",
42
+ "otp",
43
+ "2fa",
44
+ "hono",
45
+ "cloudflare-workers",
46
+ "wrangler"
47
+ ],
48
+ "author": "vtempest",
49
+ "license": "MIT",
50
+ "dependencies": {
51
+ "@hono/swagger-ui": "^0.5.2",
52
+ "@hono/zod-openapi": "^0.19.9",
53
+ "grab-api.js": "^0.9.131",
54
+ "hono": "^3.12.8",
55
+ "hono-rate-limiter": "^0.2.2",
56
+ "libphonenumber-js": "^1.12.13"
57
+ },
58
+ "devDependencies": {
59
+ "wrangler": "^4.24.0",
60
+ "eslint": "^8.55.0",
61
+ "prettier": "^3.1.0",
62
+ "vitest": "^1.0.0",
63
+ "@vitest/ui": "^1.0.0",
64
+ "supertest": "^6.3.3"
65
+ },
66
+ "repository": {
67
+ "type": "git",
68
+ "url": "https://github.com/OpenSourceAGI/appdemo-dev-tools/tree/master/packages/verify-phone-sms"
69
+ },
70
+ "homepage": "https://github.com/OpenSourceAGI/appdemo-dev-tools/tree/master/packages/verify-phone-sms"
71
+ }
@@ -0,0 +1,63 @@
1
+ #!/bin/bash
2
+
3
+ # Deployment script for SMS Verification API and Docs
4
+ # Usage: ./scripts/deploy.sh [environment] [component]
5
+
6
+ set -e
7
+
8
+ ENVIRONMENT=${1:-default}
9
+ COMPONENT=${2:-all}
10
+
11
+ echo "🚀 Starting deployment..."
12
+ echo "Environment: $ENVIRONMENT"
13
+ echo "Component: $COMPONENT"
14
+
15
+ # Function to deploy API
16
+ deploy_api() {
17
+ echo "📡 Deploying API to $ENVIRONMENT..."
18
+ if [ "$ENVIRONMENT" = "production" ]; then
19
+ npm run deploy:production
20
+ elif [ "$ENVIRONMENT" = "staging" ]; then
21
+ npm run deploy:staging
22
+ else
23
+ npm run deploy
24
+ fi
25
+ echo "✅ API deployment completed!"
26
+ }
27
+
28
+ # Function to deploy docs
29
+ deploy_docs() {
30
+ echo "📚 Building and deploying docs to $ENVIRONMENT..."
31
+ bun run build:docs
32
+
33
+ if [ "$ENVIRONMENT" = "production" ]; then
34
+ cd docs && wrangler deploy --env production && cd ..
35
+ elif [ "$ENVIRONMENT" = "staging" ]; then
36
+ cd docs && wrangler deploy --env staging && cd ..
37
+ else
38
+ cd docs && wrangler deploy && cd ..
39
+ fi
40
+ echo "✅ Docs deployment completed!"
41
+ }
42
+
43
+ # Main deployment logic
44
+ case $COMPONENT in
45
+ "api")
46
+ deploy_api
47
+ ;;
48
+ "docs")
49
+ deploy_docs
50
+ ;;
51
+ "all")
52
+ deploy_api
53
+ deploy_docs
54
+ ;;
55
+ *)
56
+ echo "❌ Invalid component. Use: api, docs, or all"
57
+ exit 1
58
+ ;;
59
+ esac
60
+
61
+ echo "🎉 Deployment completed successfully!"
62
+ echo "Environment: $ENVIRONMENT"
63
+ echo "Component: $COMPONENT"