@tuppence/http402 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 +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @tuppence/http402
|
|
2
2
|
|
|
3
|
-
Put a price on an API route
|
|
3
|
+
Put a price on an API route in one line, and let people *and agents* pay for it.
|
|
4
4
|
|
|
5
5
|
```ts
|
|
6
6
|
import { Tuppence } from "@tuppence/node";
|
|
@@ -42,7 +42,7 @@ with the `Tuppence-Client-Secret` header, and retries with
|
|
|
42
42
|
Authorization: Tuppence-Receipt <receipt_token>
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
-
|
|
45
|
+
and gets the resource. A caller who retries before paying gets the **same** payment, not a
|
|
46
46
|
new one each time.
|
|
47
47
|
|
|
48
48
|
## Why it is safe
|
|
@@ -53,7 +53,7 @@ new one each time.
|
|
|
53
53
|
- **Bound to what was bought.** The receipt names its `resource` (default `METHOD /path`) and
|
|
54
54
|
amount: a 1p receipt for another route opens nothing here.
|
|
55
55
|
- **Used once.** Its `jti` is remembered until it expires (fifteen minutes). The default store is
|
|
56
|
-
in memory
|
|
56
|
+
in memory. Running more than one process? Pass a shared `store` (`{ claim(jti, expiresAt) }`,
|
|
57
57
|
e.g. Redis `SET NX EX`).
|
|
58
58
|
- **Paid to you.** Pass `account` and receipts paid to anyone else are refused.
|
|
59
59
|
|
|
@@ -66,7 +66,7 @@ credit instead of a card:
|
|
|
66
66
|
app.get("/v1/report", http402({ tuppence, price: 50, currency: "gbp", credits: { meter: "report" } }), handler);
|
|
67
67
|
```
|
|
68
68
|
|
|
69
|
-
Your server mints the agent a token for its customer
|
|
69
|
+
Your server mints the agent a token for its customer, capped and short-lived:
|
|
70
70
|
|
|
71
71
|
```ts
|
|
72
72
|
const { token } = await tuppence.request("POST", `/v1/credits/${customerId}/tokens`, {
|
package/package.json
CHANGED