@otp-service/starter 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 +72 -0
- package/package.json +7 -6
package/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# @otp-service/starter
|
|
2
|
+
|
|
3
|
+
Opinionated factories that compose **[`@otp-service/core`](https://www.npmjs.com/package/@otp-service/core)** with **[`@otp-service/redis-store`](https://www.npmjs.com/package/@otp-service/redis-store)** and a real delivery adapter (**Twilio** SMS or **Resend** email) for the common production path.
|
|
4
|
+
|
|
5
|
+
**ESM only** · **Node.js ≥ 22** · **License:** MIT
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
Install **starter** plus the **framework** package you use for HTTP:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @otp-service/starter @otp-service/express express
|
|
13
|
+
# or: @otp-service/fastify fastify
|
|
14
|
+
# or: @otp-service/nest @nestjs/common @nestjs/core
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Starter already depends on **`@otp-service/core`**, **`redis-store`**, and both provider packages; npm will install them as transitive dependencies.
|
|
18
|
+
|
|
19
|
+
## When to use
|
|
20
|
+
|
|
21
|
+
- You want **Redis** for challenge state and a **supported** email/SMS provider with minimal wiring.
|
|
22
|
+
- You are okay with starter defaults for policy (length, TTL, max attempts); override via options where exposed.
|
|
23
|
+
|
|
24
|
+
**Avoid** starter if you need a custom store, custom signer design, or non-Resend/Twilio delivery — assemble **`createOtpService`** manually from **`@otp-service/core`** instead.
|
|
25
|
+
|
|
26
|
+
## Express example
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
import express from "express";
|
|
30
|
+
import { createTwilioSmsOtpService } from "@otp-service/starter";
|
|
31
|
+
import {
|
|
32
|
+
createGenerateChallengeHandler,
|
|
33
|
+
createVerifyChallengeHandler
|
|
34
|
+
} from "@otp-service/express";
|
|
35
|
+
|
|
36
|
+
const otpService = createTwilioSmsOtpService({
|
|
37
|
+
redis: { client: redisClient, keyPrefix: "otp:login" },
|
|
38
|
+
signerSecret: process.env.OTP_SECRET!,
|
|
39
|
+
twilio: {
|
|
40
|
+
accountSid: process.env.TWILIO_ACCOUNT_SID!,
|
|
41
|
+
authToken: process.env.TWILIO_AUTH_TOKEN!,
|
|
42
|
+
from: process.env.TWILIO_FROM!,
|
|
43
|
+
httpClient: { post: (url, i) => fetch(url, { method: "POST", headers: i.headers, body: i.body }).then(...) }
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const app = express();
|
|
48
|
+
app.use(express.json());
|
|
49
|
+
app.post("/otp/generate", createGenerateChallengeHandler({ otpService }));
|
|
50
|
+
app.post("/otp/verify", createVerifyChallengeHandler({ otpService }));
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Email path: **`createResendEmailOtpService`** with **`resend`** options — see types in **`dist/index.d.ts`**.
|
|
54
|
+
|
|
55
|
+
## Exports
|
|
56
|
+
|
|
57
|
+
| Export | Purpose |
|
|
58
|
+
|--------|---------|
|
|
59
|
+
| `createTwilioSmsOtpService` | Redis + Twilio + core |
|
|
60
|
+
| `createResendEmailOtpService` | Redis + Resend + core |
|
|
61
|
+
| `resolvePolicy` / `DEFAULT_OTP_POLICY` | Policy helpers |
|
|
62
|
+
| Re-exported **types** from core / redis / providers | Narrow surface for apps |
|
|
63
|
+
|
|
64
|
+
## More documentation
|
|
65
|
+
|
|
66
|
+
- [Starter quickstart (monorepo)](https://github.com/Suraj-H/otp-service-package-v2/blob/main/docs/guides/starter-quickstart.md)
|
|
67
|
+
- [Security](https://github.com/Suraj-H/otp-service-package-v2/blob/main/docs/guides/security.md)
|
|
68
|
+
|
|
69
|
+
## Links
|
|
70
|
+
|
|
71
|
+
- Repository: [github.com/Suraj-H/otp-service-package-v2](https://github.com/Suraj-H/otp-service-package-v2)
|
|
72
|
+
- 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/starter",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Thin starter composition helpers for the common OTP adoption path.",
|
|
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,10 +32,10 @@
|
|
|
31
32
|
"access": "public"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
|
-
"@otp-service/core": "0.1.
|
|
35
|
-
"@otp-service/provider-email-resend": "0.1.
|
|
36
|
-
"@otp-service/provider-sms-twilio": "0.1.
|
|
37
|
-
"@otp-service/redis-store": "0.1.
|
|
35
|
+
"@otp-service/core": "0.1.1",
|
|
36
|
+
"@otp-service/provider-email-resend": "0.1.1",
|
|
37
|
+
"@otp-service/provider-sms-twilio": "0.1.1",
|
|
38
|
+
"@otp-service/redis-store": "0.1.1"
|
|
38
39
|
},
|
|
39
40
|
"scripts": {
|
|
40
41
|
"build": "tsup --config tsup.config.ts",
|