@otp-service/fastify 0.1.0 → 0.1.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.
- package/README.md +53 -0
- package/package.json +4 -3
package/README.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# @otp-service/fastify
|
|
2
|
+
|
|
3
|
+
Fastify route handlers for OTP **generate** and **verify**, plus a small **error handler** helper, using an [`@otp-service/core`](https://www.npmjs.com/package/@otp-service/core) **`OtpService`**.
|
|
4
|
+
|
|
5
|
+
**ESM only** · **Node.js ≥ 22** · **License:** MIT
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @otp-service/fastify @otp-service/core fastify
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`fastify` is a **peer dependency** (`^5.0.0`).
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import Fastify from "fastify";
|
|
19
|
+
import {
|
|
20
|
+
createGenerateChallengeHandler,
|
|
21
|
+
createVerifyChallengeHandler,
|
|
22
|
+
fastifyOtpErrorHandler
|
|
23
|
+
} from "@otp-service/fastify";
|
|
24
|
+
|
|
25
|
+
const app = Fastify();
|
|
26
|
+
app.post("/otp/generate", createGenerateChallengeHandler({ otpService }));
|
|
27
|
+
app.post("/otp/verify", createVerifyChallengeHandler({ otpService }));
|
|
28
|
+
app.setErrorHandler(fastifyOtpErrorHandler);
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
### Request bodies
|
|
32
|
+
|
|
33
|
+
Same contract as Express helpers: **generate** expects `channel`, `purpose`, `recipient`; **verify** expects `challengeId`, `otp`. Optional **`mapBody`** customizes parsing.
|
|
34
|
+
|
|
35
|
+
## Exports
|
|
36
|
+
|
|
37
|
+
| Export | Purpose |
|
|
38
|
+
|--------|---------|
|
|
39
|
+
| `createGenerateChallengeHandler` | Fastify route handler |
|
|
40
|
+
| `createVerifyChallengeHandler` | Fastify route handler |
|
|
41
|
+
| `fastifyOtpErrorHandler` | Maps validation errors to HTTP responses |
|
|
42
|
+
| `FastifyOtpValidationError` | Validation error type |
|
|
43
|
+
|
|
44
|
+
## Related packages
|
|
45
|
+
|
|
46
|
+
- [`@otp-service/core`](https://www.npmjs.com/package/@otp-service/core)
|
|
47
|
+
- [`@otp-service/express`](https://www.npmjs.com/package/@otp-service/express) — same HTTP semantics on Express
|
|
48
|
+
- Guide: [docs/guides/frameworks/fastify.md](https://github.com/Suraj-H/otp-service-package-v2/blob/main/docs/guides/frameworks/fastify.md)
|
|
49
|
+
|
|
50
|
+
## Links
|
|
51
|
+
|
|
52
|
+
- Repository: [github.com/Suraj-H/otp-service-package-v2](https://github.com/Suraj-H/otp-service-package-v2)
|
|
53
|
+
- Issues: [github.com/Suraj-H/otp-service-package-v2/issues](https://github.com/Suraj-H/otp-service-package-v2/issues)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@otp-service/fastify",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Fastify route helpers for OTP generate and verify flows.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
|
-
"dist"
|
|
25
|
+
"dist",
|
|
26
|
+
"README.md"
|
|
26
27
|
],
|
|
27
28
|
"engines": {
|
|
28
29
|
"node": ">=22.0.0"
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
"access": "public"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@otp-service/core": "0.1.
|
|
35
|
+
"@otp-service/core": "0.1.1"
|
|
35
36
|
},
|
|
36
37
|
"peerDependencies": {
|
|
37
38
|
"fastify": "^5.0.0"
|