@lnbot/l402 0.1.0
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 +309 -0
- package/dist/client/index.cjs +225 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +36 -0
- package/dist/client/index.d.ts +36 -0
- package/dist/client/index.js +194 -0
- package/dist/client/index.js.map +1 -0
- package/dist/fetch-B0tuycqO.d.cts +20 -0
- package/dist/fetch-BPQpEg8M.d.ts +20 -0
- package/dist/headers-BjcT_Am-.d.ts +29 -0
- package/dist/headers-ByStTJM9.d.cts +29 -0
- package/dist/index.cjs +291 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +260 -0
- package/dist/index.js.map +1 -0
- package/dist/server/index.cjs +111 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +10 -0
- package/dist/server/index.d.ts +10 -0
- package/dist/server/index.js +79 -0
- package/dist/server/index.js.map +1 -0
- package/dist/types-FRMMn5ej.d.cts +52 -0
- package/dist/types-FRMMn5ej.d.ts +52 -0
- package/package.json +80 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Request } from 'express';
|
|
2
|
+
|
|
3
|
+
/** Data attached to `req.l402` after successful L402 verification. */
|
|
4
|
+
interface L402RequestData {
|
|
5
|
+
paymentHash: string;
|
|
6
|
+
caveats: string[] | null;
|
|
7
|
+
}
|
|
8
|
+
declare global {
|
|
9
|
+
namespace Express {
|
|
10
|
+
interface Request {
|
|
11
|
+
l402?: L402RequestData;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/** Options for the `l402.paywall()` middleware. */
|
|
16
|
+
interface L402PaywallOptions {
|
|
17
|
+
/** Price in satoshis — fixed number or async function receiving the request. */
|
|
18
|
+
price: number | ((req: Request) => number | Promise<number>);
|
|
19
|
+
/** Invoice memo / description. */
|
|
20
|
+
description?: string;
|
|
21
|
+
/** Challenge expiry in seconds. */
|
|
22
|
+
expirySeconds?: number;
|
|
23
|
+
/** Macaroon caveats to attach. */
|
|
24
|
+
caveats?: string[];
|
|
25
|
+
}
|
|
26
|
+
/** Options for the `l402.client()` factory. */
|
|
27
|
+
interface L402ClientOptions {
|
|
28
|
+
/** Max sats to pay for a single request (default: 1000). */
|
|
29
|
+
maxPrice?: number;
|
|
30
|
+
/** Total budget in sats for the period. */
|
|
31
|
+
budgetSats?: number;
|
|
32
|
+
/** Budget reset period. */
|
|
33
|
+
budgetPeriod?: "hour" | "day" | "week" | "month";
|
|
34
|
+
/** Token cache strategy (default: "memory"). */
|
|
35
|
+
store?: "memory" | "none" | TokenStore;
|
|
36
|
+
}
|
|
37
|
+
/** Pluggable token cache. */
|
|
38
|
+
interface TokenStore {
|
|
39
|
+
get(url: string): Promise<L402Token | null>;
|
|
40
|
+
set(url: string, token: L402Token): Promise<void>;
|
|
41
|
+
delete(url: string): Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/** A cached L402 credential. */
|
|
44
|
+
interface L402Token {
|
|
45
|
+
macaroon: string;
|
|
46
|
+
preimage: string;
|
|
47
|
+
authorization: string;
|
|
48
|
+
paidAt: Date;
|
|
49
|
+
expiresAt?: Date;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export type { L402ClientOptions as L, TokenStore as T, L402PaywallOptions as a, L402RequestData as b, L402Token as c };
|
package/package.json
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@lnbot/l402",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "L402 Lightning payment middleware for Express.js — paywall any API in one line",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
},
|
|
12
|
+
"require": {
|
|
13
|
+
"types": "./dist/index.d.cts",
|
|
14
|
+
"default": "./dist/index.cjs"
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"./server": {
|
|
18
|
+
"import": {
|
|
19
|
+
"types": "./dist/server/index.d.ts",
|
|
20
|
+
"default": "./dist/server/index.js"
|
|
21
|
+
},
|
|
22
|
+
"require": {
|
|
23
|
+
"types": "./dist/server/index.d.cts",
|
|
24
|
+
"default": "./dist/server/index.cjs"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"./client": {
|
|
28
|
+
"import": {
|
|
29
|
+
"types": "./dist/client/index.d.ts",
|
|
30
|
+
"default": "./dist/client/index.js"
|
|
31
|
+
},
|
|
32
|
+
"require": {
|
|
33
|
+
"types": "./dist/client/index.d.cts",
|
|
34
|
+
"default": "./dist/client/index.cjs"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"files": [
|
|
39
|
+
"dist"
|
|
40
|
+
],
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup",
|
|
43
|
+
"dev": "tsup --watch",
|
|
44
|
+
"typecheck": "tsc --noEmit",
|
|
45
|
+
"test": "vitest run",
|
|
46
|
+
"test:watch": "vitest"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@lnbot/sdk": ">=0.1.0",
|
|
50
|
+
"express": ">=4.0.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@lnbot/sdk": "^0.5.0",
|
|
54
|
+
"@types/express": "^5",
|
|
55
|
+
"express": "^5",
|
|
56
|
+
"tsup": "^8",
|
|
57
|
+
"typescript": "^5",
|
|
58
|
+
"vitest": "^3"
|
|
59
|
+
},
|
|
60
|
+
"keywords": [
|
|
61
|
+
"l402",
|
|
62
|
+
"lightning",
|
|
63
|
+
"bitcoin",
|
|
64
|
+
"paywall",
|
|
65
|
+
"micropayments",
|
|
66
|
+
"402",
|
|
67
|
+
"payment-required",
|
|
68
|
+
"express",
|
|
69
|
+
"middleware",
|
|
70
|
+
"lnbot",
|
|
71
|
+
"api-monetization",
|
|
72
|
+
"ai-agents",
|
|
73
|
+
"pay-per-request"
|
|
74
|
+
],
|
|
75
|
+
"repository": {
|
|
76
|
+
"type": "git",
|
|
77
|
+
"url": "https://github.com/lnbotdev/typescript-l402"
|
|
78
|
+
},
|
|
79
|
+
"license": "MIT"
|
|
80
|
+
}
|