@otp-service/testkit 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 +55 -0
- package/package.json +4 -3
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# @otp-service/testkit
|
|
2
|
+
|
|
3
|
+
In-memory **`ChallengeStore`**, recording **`OtpDelivery`**, deterministic OTP generator, and fixed clock helper — intended for **tests and local examples**, not production.
|
|
4
|
+
|
|
5
|
+
**ESM only** · **Node.js ≥ 22** · **License:** MIT
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save-dev @otp-service/testkit @otp-service/core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Use **`--save-dev`** so test doubles are not pulled into production installs unless you intend to.
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { createOtpService, hmacOtpSigner } from "@otp-service/core";
|
|
19
|
+
import {
|
|
20
|
+
InMemoryChallengeStore,
|
|
21
|
+
RecordingDelivery,
|
|
22
|
+
createDeterministicOtpGenerator
|
|
23
|
+
} from "@otp-service/testkit";
|
|
24
|
+
|
|
25
|
+
const delivery = new RecordingDelivery();
|
|
26
|
+
const generator = createDeterministicOtpGenerator(["123456"]);
|
|
27
|
+
const otpService = createOtpService({
|
|
28
|
+
store: new InMemoryChallengeStore(),
|
|
29
|
+
delivery,
|
|
30
|
+
otpGenerator: () => generator.nextOtp(),
|
|
31
|
+
signer: hmacOtpSigner({ secret: "test-secret" }),
|
|
32
|
+
policy: { maxVerifyAttempts: 3, otpLength: 6, ttlSeconds: 600 }
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// After generateChallenge:
|
|
36
|
+
expect(delivery.lastRequest().otp).toBe("123456");
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Exports
|
|
40
|
+
|
|
41
|
+
| Export | Purpose |
|
|
42
|
+
|--------|---------|
|
|
43
|
+
| `InMemoryChallengeStore` | Volatile `ChallengeStore` |
|
|
44
|
+
| `RecordingDelivery` | Captures `DeliveryRequest[]` / `lastRequest()` |
|
|
45
|
+
| `createDeterministicOtpGenerator` | Predictable OTP sequence |
|
|
46
|
+
| `createFixedClock` | Time-dependent tests |
|
|
47
|
+
|
|
48
|
+
## Related packages
|
|
49
|
+
|
|
50
|
+
- [`@otp-service/core`](https://www.npmjs.com/package/@otp-service/core)
|
|
51
|
+
|
|
52
|
+
## Links
|
|
53
|
+
|
|
54
|
+
- Repository: [github.com/Suraj-H/otp-service-package-v2](https://github.com/Suraj-H/otp-service-package-v2)
|
|
55
|
+
- 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/testkit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Test doubles and deterministic fixtures for OTP package testing.",
|
|
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
|
"scripts": {
|
|
37
38
|
"build": "tsup --config tsup.config.ts",
|